import re headers_str = ''' formhash: f0f241b5 qdxq: nu qdmode: 2 todaysay: fastreply: 0 ''' pattern = '^(.*?): (.*)$' for line in headers_str.splitlines(): print(re.sub(pattern, '\'\\1\': \'\\2\',', line))
import re headers_str = ''' formhash: f0f241b5 qdxq: nu qdmode: 2 todaysay: fastreply: 0 ''' pattern = '^(.*?): (.*)$' for line in headers_str.splitlines(): print(re.sub(pattern, '\'\\1\': \'\\2\',', line))
评论 (0)