Python 3.x.x one variable spread across multiple .py files -


This is not a problem with my code, but there is a general question about dragon 3.

Say you had a game with 4 parts, and the first part ( main.py ) declares a variable that says Part 2 needs to run itself Will you be able to declare that variable, then import part2 (it needs a variable to run smoothly) and the variable in the main.py Code> part2 to main.py in part2.py after importing .py .

If you want to use the variable after doing this once.

Define (print): print (voice) # part1.py import part2 if __name __ == "__ main__": part2.sound = "Yoooo" part2.scream ( ) #Output: Yoooo

If you want to be able to make variable changes later
or just do this:

  # part2.py # Gvars def defream (): print (gvars.sound) # part1.py imports part2 class gamereality: if pass __name__ == "__ main__": gvars = gameVariables () part2.gvars = gvars gvars.sound = "Yooo" part2 .scream () gvars.sound = "wow" part2.scream () #output Yooo Wha  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -