Given:
k = {'MASTER_HOST': '10.178.226.196', 'MASTER_PORT': 9999}
I want to flatten into the string:
"MASTER_HOST='10.178.226.196', MASTER_PORT=9999"
This is the ugly way that I'm achieving this right now:
result = []
for i,j in k.iteritems():
if isinstance(j, int):
result.append('%s=%d' % (i,j))
else:
result.append("%s='%s'" % (i,j))
', '.join(result)
I'm sure my developer colleagues are going to chastize me for this code. Surely there is a better way.
isinstance(False, int)
returnsTrue
, so instead offlag='False'
, you'd getflag=0
(both of which are not optimal). \$\endgroup\$