when i was reading CSV header using following code
def read_header(gram):
CSV_tag_read = csv.reader(open(\"Dataset/MALE_Training/\"+str(gram)+\"/\"+str(
Using ast.literal_eval:
>>> import ast
>>> a = "('TO', 'RP', 'TO')"
>>> b = ast.literal_eval(a)
>>> b
('TO', 'RP', 'TO')
>>> b[0]
'TO'
Or
>>> [x.strip("' ") for x in a.strip('()').split(',')]
['TO', 'RP', 'TO']
UPDATED ANSWER that corresponding to updated question:
with open('/path/to/csv-file.csv') as f:
reader = csv.reader(f, delimiter='"')
header = [column.replace("'", "") for column in header]