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
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
Wow!! 261 v. 75 lines!!
jr
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
--
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
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
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
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
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
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
>
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
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
15 matches
Mail list logo