At 12:40 PM 1/5/2006, Boyan R. wrote: >I need program to convert my string in integer. >I remember in BASIC I used val(string) command >Is there a Python equivalent ? > >Here is how it should work: >val(7) = 7 >val(bbab7) = 7 >val(aa7aa) = 7 >val( 7) = 7 > >This last is most important, currently I don't know how to >convert string " 7" to integer value 7 in my program >(those empty spaces are nasty) >btw, I'm working with random numbers, I took 7 just for example :)
int("7") -> 7 int(" 7") -> 7 int("aa7aa") ->ValueError: invalid literal for int(): aa7aa. You'd need to remove the non-digits using replace or re.sub. >what are chr() values for enter and (empty) space ? >If anybody have a table with chr() values Are you asking what numeric value passed to chr() gives Enter (etc)? If so consult any ASCII Chart. One is at http://www.lookuptables.com/. Of course Enter in ASCII is CR. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor