Is there a reverse operator to the '%' operator on string ?

Boris Boutillier boris at cantal.lip6.fr
Thu Feb 14 17:25:12 CET 2002


Yes, this is something like that that I'll have to do...
Thanks for Help

Boris Boutilier


In article <a4glqq$2oj$1 at animus.fel.iae.nl>, "Carel Fellinger"
<cfelling at iae.nl> wrote:

> Boris Boutillier <boris at cantal.lip6.fr> wrote: ...
>> Now  what I'd like to do is revert the '%' operator, I mean I want to
>> get the dictionary from the name and the Format something like :
> 
>>>NameDict = Format  op  Name .. = 'w%(width)dn%(nWord)d_%(fileName)s' op
>> "w16n12_Toto" which will give {'width':16,'nWord':12,'fileName':
>> 'Toto'}
> 
>> Is there such an operator, function or simple way to do this ?
>> Something like the 'scanf' C function ?
> 
> What about regex's, like:
> 
>>>> import re
>>>> matcher = re.compile(r"^w(\d+)n(\d+)_(.*)$").match
>>>> matcher("w16n12_Toto").groups()
> ('16', '12', 'Toto')
>



More information about the Python-list mailing list