views:

71

answers:

1

we can convert the dictionary to kw using **kw but if I want kw as str(kw) not str(dict), as I want a string with keyword arguments for code_generator,

if I pass

obj.method(name='name', test='test', relation = [('id','=',1)])

I want a function to return the string like

"name='name', test='test', relation = [('id','=',1)]"
+3  A: 

The same syntax is used to accept arbitrary keyword arguments.

def somestring(**kwargs):
  return ', '.join('%s=%r' % x for x in kwargs.iteritems())

Note that dicts are arbitrarily ordered, so the resultant string may be in a different order than the arguments passed.

Ignacio Vazquez-Abrams