interating over single element array

T. Crane tcrane at REMOVETHISuiuc.edu
Fri Jun 8 17:29:04 CEST 2007


Hi all,

Can someone please explain to me why I can't do something like this:

a = 1

for value in a:
    print str(value)

If I run this I get the error:

'int' object is not iterable

Obivously this is an absurd example that I would never do, but in my 
application the length of 'a' can be anything greater than 0, and I want to 
be able to handle cases when 'a' has only one element without coding a 
special case just in the event that len(a) = 1.

any suggestions are appreciated,
trevis 





More information about the Python-list mailing list