sscanf ?
Markus Schaber
use-net at schabi.de
Tue Nov 20 16:22:50 EST 2001
Hi,
Am Tue, 20 Nov 2001 09:17:21 -0800 schrieb Bruce Edge:
> Is there an equivalent function in python?
> I know about all the regex stuff, but I have the format string that
> was used to generate a string, which I'd like to use to decompose it
> back into it's source data:
>
> fmtstr = "%02d.%02d"
>
> str = fmtstr % ( x, y )
>
> # Now get x any y back using only str and fmtstr:
>
> (x, y ) = ?
>
>
> I suppose I could write something to convert printf style format
> strings into regexp format, but it seems like there's gotta be an
> easier way.
The problem is that there is no general solution for this problem.
How would you parse a text that was generated with a fmtstr like "%s%s"?
This is impossible. So there can't be a general scanstr function. C
provides you with a crippled one, python provides you with string.split
and regexp module.
Gruß,
Markus
--
You don't have to be Microsoft to suck... but it helps.
(Tim Hammerquist in comp.lang.python)
More information about the Python-list
mailing list