2

So I'm trying to read the variable that I need to assign from a file, I simply read the file and read it by line, and have them in string, then I use the following code to turn the string into variables:

for i in myListOfFile:
    exec(i+"=0")

This converts the strings into variables and assign them 0 value. Now I don't know how I can use the variables to increment or to do anything with them, they're set but have no idea how I can call them.

0

1 Answer 1

4

Use a dictionary like this:

variables = {}
for i in myListOfFile:
    variables[i] = 0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.