I am trying to collect strings denoting the equipment allotted to an RPG character, classified as weapons, clothing, misc. goods, etc., and annotated as ‘W’, ‘C’, ‘G’, etc., and I am having trouble using eval() to set up empty lists: listW, listC, listG, and so on.
>>>
>>> listA = []
>>> listA
[]
>>> listB = list()
>>> listB
[]
>>>
>>> C_list = list('ABCDE')
>>> C_list
['A', 'B', 'C', 'D', 'E']
>>>
>>> for c in C_list:
... eval(f'list{c} = []')
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "<string>", line 1
listA = []
^
SyntaxError: invalid syntax
>>>
When I try this code in a command shell, it works, but when I execute it in a loop with py, it fails. What am I doing wrong?
1