parsing engineering symbols

Suresh Jeevanandam jm.suresh at gmail.com
Wed Dec 21 08:40:21 EST 2005


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':-15, 'a':-18, 'z':-21, 'y':-24
> }
> 
> def myfloat(str):
>     try:
>         exp = SI_prefixes[str[-1]]
>         return float(str[:-1]) * 10**exp
>     except KeyError:
>         return float(str)
> 
> ?
> 
> </F>
> 
> 
> 



More information about the Python-list mailing list