Reputation: 11
if robotwalk <= 1 or robotwalk >= 8:
robotfall +=1
print"robotfalltrue"
robotwalk=3.5
robotlist =robotlist.append( robotsteps )
robotsteps=0
print robotlist
my question is is that how do fix this: i keep getting an error. robotlist =robotlist.append( robotsteps ). robot list has been defined as robotlist=[]
error: AttributeError: 'NoneType' object has no attribute 'append'
Upvotes: 1
Views: 57
Reputation: 19274
The method .append()
modifies the list in-place, and therefore returns nothing, hence None
. Instead, just don't assign the output of .append()
to any variable and the code will work like a charm:
if robotwalk <= 1 or robotwalk >= 8:
robotfall +=1
print"robotfalltrue"
robotwalk=3.5
robotlist.append( robotsteps )
robotsteps=0
print robotlist
Upvotes: 1
Reputation: 2068
No re-assignment. Simply do this:
robotlist.append(robotsteps)
Or, alternately:
robotlist += [robotsteps]
But I think the first is more clear.
Upvotes: 0
Reputation: 129577
append()
modifies the list in-place and returns None
. Therefore, all you need is
robotlist.append(robotsteps)
without the assignment.
Upvotes: 2