dict problem

Fredrik Lundh fredrik at pythonware.com
Mon Oct 30 05:48:09 EST 2006


Alistair King wrote:

> Is there any other way of removing double and single quotes from a
> number, as a string, to give the float value again?

help(str) describes what you can do with a string (an object of type 
'str', that is).  among the methods listed, you'll find:

>  |  strip(...)
>  |      S.strip([chars]) -> string or unicode
>  |
>  |      Return a copy of the string S with leading and trailing
>  |      whitespace removed.
>  |      If chars is given and not None, remove characters in chars instead.
>  |      If chars is unicode, S will be converted to unicode before stripping

which looks like it should be pretty useful for this specific case:

 >>> value = "'0.064250000000001084'"
 >>> value
"'0.064250000000001084'"
 >>> value.strip("'")
'0.064250000000001084'
 >>> value.strip("'\"")
'0.064250000000001084'
 >>> float(value.strip("'\""))
0.064250000000001084

</F>




More information about the Python-list mailing list