tags:

views:

44

answers:

1

I have a csv file with different headers.

name,city
john doe,chicago

Have headers as

reader = csv.DictReader(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"

A: 

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
Ignacio Vazquez-Abrams