V
V
Vadim)))2021-11-26 16:21:48
Python
Vadim))), 2021-11-26 16:21:48

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>


In main.py:

import data 
data.game_map = [0, 1, 0, 1, 0] #другие значения.


It doesn't work, the game_map variable in data.py is still None. How to fix it?
Just do not advise using json, I need EXACTLY this way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-11-26
@phaggi

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 question

Ask a Question

731 491 924 answers to any question