Re: parsing engineering symbols

2005-12-22 Thread Peter Hansen
Fredrik Lundh wrote: > Peter Hansen wrote: [the OP wrote] >>>Did you put the SI_prefixes outside the def so you could wrap the >>>whole thing in a module and reuse it in other blocks? >> >>Do "import dis" and then try "dis.dis(myfloat)" on Fredrik's version and >>on your suggested variation... (H

Re: parsing engineering symbols

2005-12-22 Thread Fredrik Lundh
Peter Hansen wrote: > > Did you put the SI_prefixes outside the def so you could wrap the > > whole thing in a module and reuse it in other blocks? > > Do "import dis" and then try "dis.dis(myfloat)" on Fredrik's version and > on your suggested variation... (Hint, it's likely more an instinct fo

Re: parsing engineering symbols

2005-12-21 Thread Jacob Rael
Wow!! 261 v. 75 lines!! jr -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing engineering symbols

2005-12-21 Thread Peter Hansen
Jacob Rael wrote: > Just a newbie, trolling. > > I like this solution. Simple, easy to understand. > > Did you put the SI_prefixes outside the def so you could wrap the > whole thing in a module and reuse it in other blocks? Do "import dis" and then try "dis.dis(myfloat)" on Fredrik's version a

Re: parsing engineering symbols

2005-12-21 Thread Jacob Rael
Just a newbie, trolling. I like this solution. Simple, easy to understand. Did you put the SI_prefixes outside the def so you could wrap the whole thing in a module and reuse it in other blocks? jr -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing engineering symbols

2005-12-21 Thread Fredrik Lundh
Bengt Richter wrote: > Nit: why not move 10** out of myfloat into SI_prefixes > (i.e., just retrieve precalculated factors)? the table I cut and pasted from only listed the exponents. if you want to prefix 1e to all the constants, be my guest. > Nit_2: No twinge of conscience shadowing str

Re: parsing engineering symbols

2005-12-21 Thread Dave Hansen
On Wed, 21 Dec 2005 19:10:21 +0530 in comp.lang.python, Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: [re: SI prefixes] > >Exactly what I wanted. > >It would be nice if the standard float function takes care of these. No, it wouldn't. Regards, -=Dave --

Re: parsing engineering symbols

2005-12-21 Thread Bengt Richter
On Tue, 20 Dec 2005 23:28:12 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Suresh Jeevanandam wrote: > >> I want to convert a string to float value. The string contains >> engineering symbols. >> >> For example, >> >> s = '12k' >> >> I want some function which would return 12000 >> function(s

Re: parsing engineering symbols

2005-12-21 Thread Suresh Jeevanandam
Exactly what I wanted. It would be nice if the standard float function takes care of these. regards, Suresh > how about: > > SI_prefixes = { > 'Y':24, 'Z':21, 'E':18, 'P':15, 'T':12, 'G':9, 'M':6, 'k':3, > 'h':2, 'd':-1, 'c':-2, 'm':-3, u'\xb5':-6, 'u':-6, 'n':-9, 'p':-12, > 'f':-1

Re: parsing engineering symbols

2005-12-20 Thread Fredrik Lundh
Suresh Jeevanandam wrote: > I want to convert a string to float value. The string contains > engineering symbols. > > For example, > > s = '12k' > > I want some function which would return 12000 > function(s) > => 12000.0 > I searched the web, but could not find any function. how about: SI_prefi

Re: parsing engineering symbols

2005-12-20 Thread Erik Max Francis
Suresh Jeevanandam wrote: > I want to convert a string to float value. The string contains > engineering symbols. > For example, > > s = '12k' > > I want some function which would return 12000 > function(s) > => 12000.0 > I searche

Re: parsing engineering symbols

2005-12-20 Thread gene tani
Suresh Jeevanandam wrote: > Hi, > I want to convert a string to float value. The string contains > engineering symbols. > For example, > > s = '12k' > > I want some function which would return 12000 > function(s) > => 12000.0 > I searched t

Re: parsing engineering symbols

2005-12-20 Thread Bengt Richter
On Tue, 20 Dec 2005 19:07:02 +0530, Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: >Hi, > I want to convert a string to float value. The string contains >engineering symbols. > For example, > > s = '12k' > > I want some function which would return 12000 >

Re: parsing engineering symbols

2005-12-20 Thread Larry Bates
Something like: def cvt(input): if input.lower().endswith('k'): return float(input[:-1])*1000 . . add your other special symbols here . return None # didn't find a match Larry Bates Suresh Jeevanandam wrote: > Hi, > I want to convert a string to float value. The stri

parsing engineering symbols

2005-12-20 Thread Suresh Jeevanandam
Hi, I want to convert a string to float value. The string contains engineering symbols. For example, s = '12k' I want some function which would return 12000 function(s) => 12000.0 I searched the web, but could not fi