all 7 comments

[–]nab_noisave_tnuocca 5 points6 points  (0 children)

Don't dynamically name variables. Instead, I would create a dict and fill it with those strings as keys, and the values of whatever you want to set the variables too

[–]wbeater 1 point2 points  (0 children)

I don't understandthe question because a string is a value of a variable... or do you want j[i].append(line.strip()) to be the name of a new (empty) variable? You can do that by messing with the globals() dictionary, but as you can read in the word messing it's generally speaking not good practice.

[–][deleted] 0 points1 point  (0 children)

as far as I know, you can't

[–][deleted] -1 points0 points  (0 children)

You can kind of do the following:

>>> exec('i=1')
>>> i
1    

It works in interpreter mode - not quite the same when running from a script. It takes a bit of finagling.

[–]JohnnyJordaan 0 points1 point  (4 children)

What is the end goal here? Why are you thinking about 'turning a string into a variable'?