real_printf

 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

  1. Bulk Insert - updated 5/9/2008 by coolie 5 years, 7 months ago
  2. Generate real random string by rafaelsdm 11 months, 2 weeks ago
  3. Generic Recievers For Signals by ericmoritz 4 years, 11 months ago
  4. Templatetag to manage GET arguments in template by DimmuR 2 years, 6 months ago
  5. Upgrade django url tags by Craterdome 1 month, 3 weeks ago

Comments

(Forgotten your password?)