一、将dictionary转换为字符串
python 3.0+
>>> k = {'MASTER_HOST': '10.178.226.196', 'MASTER_PORT': 9999}
>>> ', '.join("{!s}={!r}".format(k,v) for (k,v) in k.items())
"MASTER_PORT=9999, MASTER_HOST='10.178.226.196'"
python 2.X
', '.join("%s=%r" % (key,val) for (key,val) in k.iteritems())区别于str()
>>> k = {'MASTER_HOST': '10.178.226.196', 'MASTER_PORT': 9999}
>>> str(k)
"{'MASTER_PORT': 9999, 'MASTER_HOST': '10.178.226.196'}"
二、
数字转换为以十六进制字符串
hex():注意转换的字符串以0x开头
'{:x}'.format(int):转换后去掉了前面的0x
十六进制的字符串转为十进制数字
>>> int('0xff',16)
255
>>> int('ff',16)
255