how to iterate over sequence and non-sequence ?

stef mientki stef.mientki at gmail.com
Thu Oct 18 19:24:09 EDT 2007


hello,

I generate dynamically a sequence of values,
but this "sequence" could also have length 1 or even length 0.

So I get some line in the form of:
      line = '(2,3,4)'
      line = ''
      line = '(2)'
(in fact these are not constant numbers, but all kind of integer 
variables, coming from all over the program, selected from a tree, that 
shows all "reachable" variables)

So in fact I get the value from an exec statement, like this
      exec 'signals = ' + line

Now I want to iterate over "signals", which works perfect if there are 2 
or more signals,
but it fails when I have none or just 1 signal.
    for value in signals :
        do something

As this meant for real-time signals, I want it fast, so (I think) I 
can't afford extensive testing.

Any smart solution there ?

thanks,
Stef Mientki



More information about the Python-list mailing list