sscanf ?

Erik Max Francis max at alcyone.com
Tue Nov 20 16:00:11 EST 2001


Bruce Edge wrote:

> Additionally, after parsing with re, I still need to convert to
> integers,
> which is a PITA when you consider the "%x" case. The format string
> "knows"
> that this is in hex, using re, I get back say a string which I still
> need
> to dtermine the number base and convert.

You can use the int-with-arg form for converting strings to integers
other than in base ten.

> I'm not arguing :)
> It's just that in this one tiny case, scanf would have been the
> perfect
> tool.

It wouldn't be hard to write a simple wrapping script that takes a
printf format string, converts it to a regular expression, does a match
against a string, then pulls out the arguments and converts them to
types as appropriate.  But one might just as well be using regular
expressions directly in the first place.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Laws are silent in time of war.
\__/ Cicero
    Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
 An Esperanto reference for English speakers.



More information about the Python-list mailing list