HELP! Just when I get one thing working, something else doesn’t work! Again, I’m sure it’s simple to experienced eyes, but I’m struggling! This is the code where I generate my lists and the data for said lists.
#Frame Creation
allframes = []
for n in range (0, (workingframes*archnodes*3)):
allframes.append(n)
frames = allframes
print frames
#Frame Population
for f in range (0, workingframes):
if f<=(workingframes/2):
for x in range (0, (archnodes)):
frames[((archnodes*3)+f)].insert(((archnodes*3)+f), (archstartred[x]))
frames[((archnodes*3)+f+workingframes)].insert(((archnodes*3)+f+workingframes),(archstartgrn[x]))
frames[((archnodes*3)+f+workingframes*2)].insert(((archnodes*3)+f+workingframes*2),(archstartblu[x]))
for y in range (0, nodesperframe):
archstartred.pop()
archstartgrn.pop()
archstartblu.pop()
archstartred.insert(0, backred)
archstartgrn.insert(0, backgrn)
archstartblu.insert(0, backblu)
else:
for y in range (0, nodesperframe):
archstartred.pop(0)
archstartgrn.pop(0)
archstartblu.pop(0)
archstartred.append(backred)
archstartgrn.append(backgrn)
archstartblu.append(backblu)
for x in range (0, (archnodes)):
frames[(archnodes*3)+f].insert((archnodes*3), (archstartred[x]))
frames[(archnodes*3)+f+workingframes].insert(((archnodes*3)+1),(archstartgrn[x]))
frames[(archnodes*3)+f+workingframes*2].insert(((archnodes*3)+2),(archstartblu[x]))
I keep getting this lovely error:
AttributeError: 'int' object has no attribute 'insert'
I plan on converting the list to an array after the list is populated so that I can have it manipulated the way it needs to be. I’m sure there’s a much easier way to do this, but I don’t know and I’m new to Python!
These expressions
frames[((archnodes*3)+f)](all 3 versions) evaluate to be integers and you are trying to call aninsert()method on them which is the cause of your error.fis an integer created in the enclosing for loop, and the wayarchnodesare used in the first for loop also implies they are numbers.framesis a list of numbers too created in your first loop, so you are indexing into a list of numbers and then trying to call theinsert()method on the specific number in the list. As the error message states,'int' object has no attribute 'insert'the type
intdoes not have aninsertmethod.Update re comment above:
You can add/remove/insert items to the list, but you can’t add/remove/insert to an integer. See this brief tutorial/reference on lists. So for instance to insert an item into a list you’d use this methods/approach:
so in your case
not
I hope this helps.