def format_string(string, context):
 def lookup_arg(match):
  x = context[(match.group(1) or match.group(2))]
  if (not isinstance(x, string_types)):
   x = type(string)(x)
  return x
 return _format_re.sub(lookup_arg, string)

def format_string ( string , context ) : def lookup_arg ( match ) : x = context [ ( match . group ( 1 ) or match . group ( 2 ) ) ] if ( not isinstance ( x , string_types ) ) : x = type ( string ) ( x ) return x return _format_re . sub ( lookup_arg , string )
formats a string in the same way that the % formatting would use .