Re: String/Number Conversion

2008-09-06 Thread Scott David Daniels
Andreas Hofmann wrote: I've got some strings, which only contain numbers plus eventually one character as si-postfix (k for kilo, m for mega, g for giga). I'm trying to convert those strings to integers, with this function: Why bother to always switch the case if you only use a few values? Als

Re: String/Number Conversion

2008-09-06 Thread Andreas Hofmann
Thanks a lot, I got it working now. Thanks also to the other guys, your numerous hints were really valuable! Kind regards, Andy John Machin schrieb: On Sep 7, 7:04 am, Andreas Hofmann <[EMAIL PROTECTED]> wrote: Hello Folks! I've got a little problem here, which which really creeps me out at t

Re: String/Number Conversion

2008-09-06 Thread bearophileHUGS
Andreas Hofmann, there are several problems in your code: > if type(value) is str: Better to use isinstance() and to compare it with basestring instead. > value.upper() This does nothing, python strings are immutable, so they don't get changed in-place, so you have to

Re: String/Number Conversion

2008-09-06 Thread John Machin
On Sep 7, 7:29 am, Wojtek Walczak <[EMAIL PROTECTED]> wrote: > On Sat, 06 Sep 2008 23:04:14 +0200, Andreas Hofmann wrote: > >                  if mult is 1: > >                            ^^ > You're testing for identity, not for equality. > Change it to "if mult == 1". Is it alright now? > Althou

Re: String/Number Conversion

2008-09-06 Thread John Machin
On Sep 7, 7:04 am, Andreas Hofmann <[EMAIL PROTECTED]> wrote: > Hello Folks! > > I've got a little problem here, which which really creeps me out at the > moment. > I've got some strings, which only contain numbers plus eventually one > character as si-postfix (k for kilo, m for mega, g for giga).

Re: String/Number Conversion

2008-09-06 Thread Wojtek Walczak
On Sat, 06 Sep 2008 23:04:14 +0200, Andreas Hofmann wrote: Hi, > I've got a little problem here, which which really creeps me out at the > moment. > I've got some strings, which only contain numbers plus eventually one > character as si-postfix (k for kilo, m for mega, g for giga). I'm trying

Re: String/Number Conversion

2008-09-06 Thread josh logan
On Sep 6, 5:04 pm, Andreas Hofmann <[EMAIL PROTECTED]> wrote: > Hello Folks! > > I've got a little problem here, which which really creeps me out at the > moment. > I've got some strings, which only contain numbers plus eventually one > character as si-postfix (k for kilo, m for mega, g for giga).

String/Number Conversion

2008-09-06 Thread Andreas Hofmann
Hello Folks! I've got a little problem here, which which really creeps me out at the moment. I've got some strings, which only contain numbers plus eventually one character as si-postfix (k for kilo, m for mega, g for giga). I'm trying to convert those strings to integers, with this function: