Parsing strings -> numbers

Tuang tuanglen at hotmail.com
Mon Nov 24 15:55:10 EST 2003


I've been looking all over in the docs, but I can't figure out how
you're *supposed* to parse formatted strings into numbers (and other
data types, for that matter) in Python.

In C#, you can say

int.Parse(myString)

and it will turn a string like "-12,345" into a proper int. It works
for all sorts of data types with all sorts of formats, and you can
pass it locale parameters to tell it, for example, to parse a German
"12.345,67" into 12345.67. Java does this, too.
(Integer.parseInt(myStr), IIRC).

What's the equivalent in Python?

And if the only problem is comma thousand-separators (e.g.,
"12,345.67"), is there a higher-performance way to convert that into
the number 12345.67 than using Python's formal parsers?

Thanks.




More information about the Python-list mailing list