Changing variables in separate Python files -


so found out today can import variables other python files. example, can have variable green = 1, , have separate file use variable. i've found helpful functions.

so, here's question. i'm sorry if title didn't much, wasn't entirely sure called. want program ask player or name is. once player has answered, want variable stored in separate python file, "player_variables.py", every time want player's name, instead of having go from game import name, can use from player_variables import name, make easier.

i understand lazy man's question, i'm trying learn as could. i'm still new, , i'm sorry if question ridiculous. :). help, appreciate it. (be nice me!)

from question, think you're confusing ideas variables , values of variables.

1) creating python file variable names allows access values of variables defined therein. example:

# myvariables.py name = 'steve'  # main.py import myvariables print myvariables.name 

since requires variables defined global, solution not ideal. see link more: https://docs.python.org/2/reference/simple_stmts.html#global

2) however, question states you want program save variable of user-entered value in python file, thing entirely that's metaprogramming in python - program outputting python code, in case file same name variables python file.

from above, if means you're accessing , updating variables values, simpler idea have config file can loaded or changed @ whim. metaprogramming necessary when need it.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -