1
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'

3 Answers 3

2

append() modifies the list in-place and returns None. Therefore, all you need is

robotlist.append(robotsteps)

without the assignment.

Sign up to request clarification or add additional context in comments.

Comments

1

No re-assignment. Simply do this:

robotlist.append(robotsteps)

Or, alternately:

robotlist += [robotsteps]

But I think the first is more clear.

1 Comment

Thanks. Caught that and put the brackets in. And I see you answered first. Cheers! :-)
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.