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

Boris Boutillier boris at cantal.lip6.fr
Thu Feb 14 12:11:08 CET 2002


Hi all,

I use a format string and a dictionnary to create a name as follow :
>Format = 'w%(width)dn%(nWord)d_%(fileName)s'
>NameDict = {'width' : 16, 'nWord' : 12, 'fileName' : 'Toto'}

>Name = Format % NameDict   # This gives "w16n12_Toto"

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 ?


Boris Boutillier



More information about the Python-list mailing list