简体   繁体   中英

List Index & NoneType Error

I have a python list structure which resembles this;

seq = ['l', 'm', 'n', 'o', 'p', 'q', 'r', 's']

I increment a pointer so that after certain events in my code I can access the next item of my list (which does not interfere with or mention the list) which is passed into a function to return a and b as below;

pointer+=1 
a, b= get_instruction(seq[pointer])

I get the error;

 TypeError: 'NoneType' object is not iterable

Why is this? The variable pointer is set to 0 at the start of the script and it seems to break as soon as I put it to one. Pointer increments without an error and can be seen to increment. Why will it not simply return the a and b relevant to the item at the pointed to item in the list??

I would think this means that get_instructions() is returning nothing. It needs to return a proper variable. I can't tell you anything else unless you show us the get_instructions() function. What I can tell you is that it is very likely a problem in that function

You are trying to unpack a None value into two variables rather than an iterable of length two:

a, b = get_instruction(seq[pointer]) # a, b = None

For some reason, your function is evaluating to None. You'll have to correct this behavior in the function's contents in order to unpack correctly. Remember, you'll need an iterable with two items.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM