Smartsheet Data Tracker: AttributeError: 'dict' object has no attribute 'append'

David picture David · Apr 11, 2014 · Viewed 7.4k times · Source

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)

Answer

anon582847382 picture anon582847382 · Apr 11, 2014

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.