sscanf ?
Bruce Edge
bedge at troikanetworks.com
Tue Nov 20 13:39:24 EST 2001
In <3BFAA0FC.EB3CB91B at alcyone.com>, Erik Max Francis wrote:
> Bruce Edge wrote:
>
>> 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 ) = ?
>
> x, y = map(int, str.split('.'))
>
OK, that works for this case, I was looking for something more generic.
What about for this case:
fmtstr = "x=%02d and y is %02d"
currently I'm looking at converting the %02d into \d{:2} for use with the
re module.
-Bruce.
More information about the Python-list
mailing list