I want to append something to a list which has the same (variable) name as a given string.
Background:
I got a comma-separated values file, where val[0] is a value like a list I got actually in Python.
Example code.py:
foo = []
bar = []
with open('csv.txt','r') as fs:
for line in fs.read().splitlines():
line=line.split(';')
line[0].append(data) # where line[0] got the value 'foo' or 'bar'
Example csv.txt:
foo;some;data
bar;some;other data
I know this is bad practice. The file is extra formatted for this code, so there will be no issue (for me). I don't want to use Python 3.10-alpha for match case and I got many lines with if,elif
statements, which makes my code very illegible.
Anyone know a solution for this? I tried exec()
, but it don't works.