Re: [Tutor] why are these two uses different?

Magnus Lycka magnus at thinkware.se
Mon Mar 1 10:54:32 EST 2004


> Each command triggers a whole sequence of serial writes and reads. This
> works fine. Now I want to create a section which allows me to do them
> individually. 

I guess here is where the problem lies. I'm guessing that
you have a loop somewhere in your code, where you loop
over something like ['1d', 'ff', 'c2'] in the working case. 
Now, you loop over '1d' instead, and that's just the same 
as looping over ['1', 'd']. Make sure to feed your loop with 
a list or tuple instead, and I think it will work. ['1d'] or 
('1d',) should work, but notice that ('1d') is *not* a tuple, 
just a string in parenthesis.

E.g.

>>> x = '1d'
>>> for i in x: print i

1 
d
>>> for i in (x): print i

1 
d
>>> for i in (x,): print i

1d
>>> for i in [x]: print i

1d


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se



More information about the Tutor mailing list