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

Carel Fellinger cfelling at iae.nl
Thu Feb 14 10:41:14 EST 2002


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')

-- 
groetjes, carel



More information about the Python-list mailing list