PYTHON string format
1. in python3 use dict to formate strings:
>>>print(“%(a)s” % {'a’:'b’})
b
>>>a = ‘b’
>>>print(“%(a)s” % locals())
b
2. in Python 2.6 on up you can use the new format() method on strings:
>>>'{a}'.format(a = ‘spam’)
'spam’
3. using string
>>>import string
>>>template = string.Template(“$scheme://$host:$port/$route#$fragment”)
>>>template.substitute(scheme = ”http”, host = ”google.com”, port = “80”, route = “”, fragement = “”)
'http://google.com:80/#

浙公网安备 33010602011771号