1 2 3 4 5 6 7 8 9 10 11 12 13
| import re
old_headers =''' Accept: text/html Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9,en;q=0.8 '''
pattern = '^(.*?):[\s]*(.*?)$' headers = "" for line in old_headers.splitlines(): headers += (re.sub(pattern,'\'\\1\': \'\\2\',',line)) + '\n' print(headers[:-2])
|