I'm a big fan of using the % (modulo / string formatting operator thingy), for example:
>>> fileName = "par1-%d_par2-%.1f_%s.dat" % (par1, par2, suffix)
par1-5_par2-0.1_hello.dat
Is there any package/function which allows you to reverse this process to extract the regex patterns from the string? e.g.
>>> magicFunction(fileName, "par1-%d_par2-%.1f_%s.dat")
1, 0.1, 'hello'
Aucun commentaire:
Enregistrer un commentaire