Ask coding questions

← Back to all posts
Python 3: Changing variables in main.py and updating in other files
Muffinlavania (1421)

So I recently started making Connect 4 in python, and something i found was this:
I have a variable boardslots, and it is defined in main.py
Board.py contains the function which determines if you win, using the variable boardslots from main.py
My problem is:
In the main game loop the boardslots variable changes according to your move, but in Board.py it does not change, it does not update that variable in Board.py, but it does in main.py.
Does anyone know how to update a variable from main.py in another file? How to update a variable in main.py, and see those changes in another file?

Please give advice in the comment section, and if it really cant be done i will just move it to main.py

Answered by Coder100 (12434) [earned 5 cycles]
View Answer
Commentshotnewtop
Coder100 (12434)

You are better off with having something like:

def executeThisCode(with,these,variables):
  # hehe
Muffinlavania (1421)

@CHRISTOPHERTIPP this is just to give you a notification, but i responded in My maze project. By the way, I sent this at 10:20 PM, i dont know what timezone your in but im in EST

Muffinlavania (1421)

@CHRISTOPHERTIPP also i will be on repl.it around 8:00AM on my time

Muffinlavania (1421)

@R16 if you see this reply when you can

R16 (4)

@Muffinlavania i see this......like shall we do it today at the time which you decided earlier

Muffinlavania (1421)

@R16 umm well i can do it any time after 8:30 pm for you, so just pick a time! Right now its 4am... lol i got to go to bed

R16 (4)

@Muffinlavania let's do it at like 10:00 pm for me..........ummm you okay with that?

Muffinlavania (1421)

@R16 yea sure! That will be about 12:30pm for me

R16 (4)

@Muffinlavania hey what about today?

Muffinlavania (1421)

@R16 yea, i can do it today. Tomorrow i can also do it, but at 10:30 pm for you

R16 (4)

@Muffinlavania let's do it today at 10:00

R16 (4)

@Muffinlavania bruh I am really sorry the network 😵
I am sure it will not happen tomorrow.

Muffinlavania (1421)

@R16 its fine, but can we do it at 10:30pm for you, or 1pm for you

R16 (4)

@Muffinlavania for TOMORROW 10:30 would be cool

Muffinlavania (1421)

@R16 yea, see ya in 4 hours!

R16 (4)

@Muffinlavania hey can we do it right now like it 9 cause I don't think I will be free at 10 because I have got a test tomorrow

Muffinlavania (1421)

@R16 oh sorry... i have lunch right now thats why i can do it

R16 (4)

@Muffinlavania Hey I have left some message for you in .env so please see it and contact me.

Muffinlavania (1421)

@R16 i cant contact you on gmail, My school blocked it on my computer.... so i have to talk to you like this or on modules. SO i can do it any time from right now to 10pm for me, or in like 6 hours. SO yea if you want to do it anytime just tell me.

R16 (4)

@Muffinlavania It is really messed up dude!!!
okay let's confirm a particular timing so that we can do it.

Muffinlavania (1421)

@R16 yea, sorry. I could not do it this weekend, but today i can for half an hour at 1:00pm, or 10:30pm for you. Tomorrow i cant, and the day after that I can again, then i cant, then i can.

R16 (4)

@Muffinlavania ok cool! so we can do today at 10:30

Muffinlavania (1421)

@R16 yea sure, but i might be only able to do it for like 20 minutes

R16 (4)

@Muffinlavania I'm waiting...........

Coder100 (12434)

nope, not possible.

Muffinlavania (1421)

@Coder100 bruh moment... it is possible. I was just being stupid and testing the wrong thing, it was working all along. But i did take your advice and did this

import __main__ as thing2
def win(boardslots=thing2.boardslots)