[Python-bugs-list] [ python-Bugs-807107 ] "TypeError: iteration
over non-sequence" for list of strings
SourceForge.net
noreply at sourceforge.net
Wed Sep 17 12:37:27 EDT 2003
Bugs item #807107, was opened at 2003-09-16 08:11
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=807107&group_id=5470
Category: Parser/Compiler
Group: Trash
>Status: Closed
>Resolution: Invalid
Priority: 1
Submitted By: Geir M. Koien (gmkoien)
Assigned to: Nobody/Anonymous (nobody)
Summary: "TypeError: iteration over non-sequence" for list of strings
Initial Comment:
The following code gives me the "TypeError: iteration
over non-sequence" error.
I don't see why this shouldn't work.
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200
32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more
information.
list = ["I am a boy", "You are a girl"]
for i in len(list):
line = list[i]
Traceback (most recent call last):
File "<pyshell#39>", line 1, in ?
for i in len(list):
TypeError: iteration over non-sequence
***
If I take the steps manually it works....
>>> len(list)
2
>>> list[0]
'I am a boy'
>>> list[1]
'You are a girl'
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2003-09-16 09:17
Message:
Logged In: YES
user_id=33168
You need to do either:
for i in range(len(list)):
line = list[i]
OR
for line in list:
...
The error message is telling you that you are trying to
iterate over an int which is returned from len(list). Hope
this helps.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=807107&group_id=5470
More information about the Python-bugs-list
mailing list