[Tutor] String to integer?

Bernard Lebel python at bernardlebel.com
Wed Sep 1 15:00:36 CEST 2004


Personally I'd consider using a dictionary for that. Assign the letter (the
key) to the number (the value).


Cheers
Bernard


----- Original Message ----- 
From: "adam" <adam at monkeez.org>
To: <tutor at python.org>
Sent: Wednesday, September 01, 2004 2:54 PM
Subject: [Tutor] String to integer?


> I have a list which holds all the letters of the alphabet. I want to
> create a button (wxPython) for each of these letters and then give the
> button an ID (count - which is an integer). However, I would like the ID
> to be driven by the list (which is string). See code below.
>
> What's the easiest way of creating an integer which is based on a value of
> a letter? I really don't mind if it was based on the ascii code, or
> another equivalent.
>
> Thanks in advance.
>
> Adam
>
> alphabet = ['a','b','c','d','e' ... and so on.
> for i in alphabet:
>     count = count + 1
>     bmp = wxBitmap('alphabet_graphics/' + i + '.bmp', wxBITMAP_TYPE_BMP)
>     self.grafic =wxBitmapButton(self, count,bmp,wxPoint(160,20),
> wxSize(bmp.GetWidth()+10,bmp.GetHeight()+10))
>     self.sizer2.Add(self.grafic,1,wxEXPAND)
>     EVT_BUTTON(self, count, self.ButtonPushed)
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>




More information about the Tutor mailing list