1 2 3 4 5 6 7 8 9 10 11 | _string_re = compile(r'%(\d+)\$([\d\.]*[diufFeEgGxXoscpn%])')
def real_printf(string, values=None):
if not values:
return string
if type(values) not in [tuple, list]:
values = (values,)
_string = _string_re.sub('%(\g<1>)\g<2>', string)
if _string == string:
return string % values
else:
return _string % dict((str(i+1), values[i]) for i in xrange(len(values)))
|
More like this
- Bulk Insert - updated 5/9/2008 by coolie 5 years, 7 months ago
- Generate real random string by rafaelsdm 11 months, 2 weeks ago
- Generic Recievers For Signals by ericmoritz 4 years, 11 months ago
- Templatetag to manage GET arguments in template by DimmuR 2 years, 6 months ago
- Upgrade django url tags by Craterdome 1 month, 2 weeks ago
Comments