python list append gives a error: AttributeError: 'function' object has no attribute 'append'

14,556

It seems you have a function in your code that is shadowing Python's built-in function named list.

Share:
14,556
peztherez
Author by

peztherez

Updated on June 12, 2022

Comments

  • peztherez
    peztherez almost 2 years

    I have list = [] and I am adding an element to it using self.list.append('test') and I get this error - AttributeError: 'function' object has no attribute 'append'

    The other list that I have defined append just fine, any ideas?

  • SethMMorton
    SethMMorton almost 11 years
    I'd like to point out that everyone using python has a function called list in their code... it's the python builtin list. This is a perfect example of why it's bad practice to give variables names that shadow builtin functions.