list in loop, Nonetype errors
        Posted  
        
            by 
                user2926755
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user2926755
        
        
        
        Published on 2013-10-28T04:49:15Z
        Indexed on 
            2013/10/28
            9:54 UTC
        
        
        Read the original article
        Hit count: 214
        
python-2.7
Here is my Code
def printList(stringlist):
    empty = []
    if stringlist is None:
        print empty
    else:
        print stringlist
def add (stringlist, string):
    string = [] if string is None else string
    if stringlist is not None:
        stringlist.insert(0, string)
    else:
        stringlist.append(1)
it somehow appears "AttributeError: 'NoneType' object has no attribute 'append'"
I was originally looking for the code to be run like this:
>>> myList = None
>>> printList(myList)
[]
>>> for word in ['laundry','homework','cooking','cleaning']:
myList = add(myList, word)
printList(myList)
[laundry]
[homework, laundry]
[cooking, homework, laundry]
[cleaning, cooking, homework, laundry]
© Stack Overflow or respective owner