开发者

Python csv tags

开发者 https://www.devze.com 2022-12-20 08:38 出处:网络
I have a csv file with different headers. name,city john doe,chicago Have headers as reader = csv.DictReader开发者_StackOverflow社区(open(PATH_FILE),skipinitialspace=True)

I have a csv file with different headers.

name,city
john doe,chicago

Have headers as

reader = csv.DictReader开发者_StackOverflow社区(open(PATH_FILE),skipinitialspace=True)
headers = reader.fieldnames

How will you run a regex that whenever a tag [name] was to be proceesed it will show "john doe"


You could use re.sub() with a function passed as repl, or you could just use string interpolation with a mapping:

print 'My name is %(name)s' % rowdict
0

精彩评论

暂无评论...
验证码 换一张
取 消