Answer the question
In order to leave comments, you need to log in
How to change a variable in another script?
I have a main.py file and a data.py file. I need to change a variable in data.py.
I write the following code in the data.py file:
<br>
game_map = None #почему-то отображается <br>, не знаю почему(<br>
import data
data.game_map = [0, 1, 0, 1, 0] #другие значения.
Answer the question
In order to leave comments, you need to log in
Because you didn't change it. You have a reference to an object in memory, and you have changed the reference to another object in memory. The memory is not mapped to a file on disk in any way.
You need to end up opening the file on disk as a text file for reading; read its contents into memory; find the desired line there and replace it with the desired one; open the file for writing and save the new version there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question