For example, there is such a code

for i in range(maxRecordsToParse): chunkH = list(chunkedHrefs[i]) chunkR = list(chunkedReceived[i]) record = Record(received=chunkR[0], posted=chunkR[1], operator_name=chunkR[2], number=chunkR[3], operator_contact=chunkR[4] +' ' + chunkR[5], status=chunkH[0], status_date=chunkR[8], well_name_number=chunkR[9] + ' ' + chunkR[10], document_link=chunkH[1], type_of_permit=chunkR[11], well_location=chunkH[2], footage_call=str(chunkR[13]), objective_formation=chunkR[14], proposed_td=chunkR[15], field=str(chunkR[16]) + ' ' + str(chunkR[17]), county=chunkR[18]) filledRecords.append(record) 

Record class code

 class Record: def __init__(self, received, posted, operator_name, number, operator_contact, status, status_date, well_name_number, document_link, type_of_permit, well_location, footage_call, objective_formation, proposed_td, field, county): self.received = received self.posted = posted, self.operator_name = operator_name, self.number = number, self.operator_contact = operator_contact, self.status = status, self.status_date = status_date, self.well_name_number = well_name_number, self.type_of_permit = type_of_permit self.document_link = document_link self.well_location = well_location, self.footage_call = footage_call, self.objective_formation = objective_formation, self.proposed_td = proposed_td, self.field = field, self.county = county 

As a result, 90% of the fields in the Record class are tuple, and the first value is the search string, and the second is empty. For example ('GRAND VALLEY',)

  • First, correct the formatting of the code, secondly, it is not clear what the elements chunkedHrefs[i] and chunkedReceived[i] ? Apparently, there is a tuple . - zed
  • Python, like any other PL, does not do anything about which it is not asked. Understand the chunkedHrefs and chunkedReceived . - andy.37
  • chunkedHrefs and chunkedReceived is just a sheet of sheets [['string', 'string', ....], ['string', 'string', ....], ...] - Yaktens Teed
  • Why then do you wrap them again in the list ? - zed

1 answer 1

In the code of your class Record, you need to remove the commas at the end of the lines.

Expression type

 x, 

interpreted by the interpreter as stupid from one element. By the way, this is exactly stupid from a single element, and not from two elements, where the second is empty.

A comma at the end of a line should be placed only if you break a sequence into several lines. But if you have not a multi-line sequence, but a single element, then a comma is not needed after it.

  • Feyspalm. Indeed, it was stupid. Only moved from Sharpie to Python and worked all night, overlooked, probably XD - Yaktens Teed