sscanf ?

Bruce Edge bedge at troikanetworks.com
Tue Nov 20 14:56:36 EST 2001


In <3BFAAD1E.9E9AF618 at alcyone.com>, Erik Max Francis wrote:

> Bruce Edge wrote:
> 
>> OK, that works for this case, I was looking for something more generic.
> 
> There is no scanf-like parsing service in Python.  Which is fine, since
> scanf has problems.  If you want general parsing, you should use regular
> expressions; that's what they're there for.
> 
> 
Yeah, I know that scanf is not an ideal tool, but in this case, I only
have the format string and the data. A regexp str is an additional data
item that I have to put in my class.

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.

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

-Bruce.



More information about the Python-list mailing list