[Tutor] why are these two uses different?

Stanfield, Vicki {D167~Indianapolis} vicki.stanfield at ROCHE.COM
Mon Mar 1 11:08:10 EST 2004


I had tried '1D'. Now I have tried to input [1D], ['1D'] but both
generate the 

ValueError: list.index(x): x not in list

when I hit the
'fcommand=self.Dict.keys()[self.Dict.values().index(hexval)]' line. It
doesn't seem to matter how I enter the data into the wxTextEntryDialog,
it doesn't match. Given the following dictionary excerpt:

 self.Dict=('\x78':'78','\x65':'65','\x60':'60',<SNIP>'\x1D':'1D')

What needs to be entered into the wxTextEntryDialog to make it match
this dictionary?

--vicki


-----Original Message-----
From: Magnus Lycka [mailto:magnus at thinkware.se] 
Sent: Monday, March 01, 2004 10:55 AM
To: Stanfield, Vicki {D167~Indianapolis}; tutor at python.org
Subject: Re: [Tutor] why are these two uses different?


> 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