问题
I am new to Python and I'm working with Smartsheet Data Tracker to update a sheet from a CSV file.
I have problems about the array list management in Python; I don't know about this error, I was reading about this error on StackOverflow but I don't understand it:
The error:
"File "C:\Users\David\DataTraker\connectors\CSVCon.py", line 61, in __init__
self.csvData.append(readerRow)
AttributeError: 'dict' object has no attribute 'append'"
And my code:
def __init__(self, sourceConfig):
self.csvData = []
self.csvData = {"sourceId": "siniestros",
"connectorClassName": "CSVCon",
"fileName": "siniestros.csv",
"isStrict": False}
for readerRow in sourceReader:
self.csvData.append(readerRow)
回答1:
What is going wrong is that you create a list
to which you would like to append
later. However you overwrite that afterwards with a dictionary, to which you cannot append. This is why you get an AttributeError
.
To fix this, I would rename your dictionary (self.csvData={stuff}
) that you created after your list
to something else such as self.meta
, perhaps. Alternatively, you could rename your list
.
It doesn't matter which, you just need to remove the naming conflict so both variables can co-exist in the namespace.
回答2:
Actually, this was more an issue of poorly commented code in the Data Tracker project that caused the confusion in the CSVCon.py file. The CSV Configuration settings that are in those comments are an example of what should be in the settings/sources.json
file.
The Configure Source section in the project documentation provides some more detail on setting up your source in the sources.json file.
There is also a section with an explanation of the CSV source specifically.
The confusing commenting has been updated to be more clear.
来源:https://stackoverflow.com/questions/23016559/smartsheet-data-tracker-attributeerror-dict-object-has-no-attribute-append