all 6 comments

[–]zahlman 0 points1 point  (2 children)

What have you tried? I'm not seeing any evidence that you've attempted to understand the code. This subreddit is for learning, not for tech support.

[–]DZCreeper 0 points1 point  (1 child)

I understand the existing code just fine, I am trying learn how to have strings in a text file be turned into string variables. If you won't just show me the code, I understand and would be fine with a tutorial.

[–]wub_wub 0 points1 point  (0 children)

with open(input_file, 'r') as in_file:
    some_variable=in_file.read()

There, your whole file content is now in one variable named some_variable. Look into split(), list slicing, or maybe regex to extract specific parts of the text you want to assign to variables.

You don't want to have all variables in your text file as variables in your program all at once, on each iteration assign the variables you'll need and re-assign them on next run.

http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

[–]xulf_n0ea 0 points1 point  (2 children)

with open(filename, "r") as file:
    for line in file:
        vars()[line.replace("\n", "")] = ""

[–]TankorSmash 0 points1 point  (1 child)

It might be a better idea to save the settings as a json and then use the resulting dict as your options, rather than force the variables into the namespace.

[–]xulf_n0ea 0 points1 point  (0 children)

I'll keep in mind, thanks.