Python Forum
Questions on variable changing between files.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Questions on variable changing between files.
#11
(Apr-24-2017, 07:04 AM)Sello Wrote:
# This is File A
from fileb import bvar

bvar = 10

There seem to be a lot of assumptions that you want to save that value to the original file, so the next time you open up fileb, it'd be 10 instead of whatever it used to be.  I'm not sure that's what you're asking.  If you just want to change it while it's running, sort of like a config value, then work with the file as a module directly, instead of only importing the single variable.  Like so:

#file a
import fileb

print(fileb.bvar) # 5, maybe

fileb.bvar = 10

print(fileb.bvar) # 10 here, and also 10 for anything in fileb that uses it
Although you'd need a pretty good reason to want to do that, since it could easily make reading fileb and understanding why the output is as it is fairly complicated.
Reply


Messages In This Thread
RE: Questions on variable changing between files. - by nilamo - Apr-24-2017, 05:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Keeping a value the same despite changing the variable it was equated to TheTypicalDoge 2 1,480 Mar-13-2022, 10:50 PM
Last Post: Yoriz
  changing Python files to .exe alok 2 2,252 Jul-20-2021, 02:49 PM
Last Post: alok
  Changing a variable's name on each iteration of a loop rix 6 84,985 Jan-03-2020, 07:06 AM
Last Post: perfringo
  how write variable in files and retreive it frank 2 2,073 Jan-30-2019, 12:53 AM
Last Post: frank
  int(variable) not changing variable to an integer StoopidChicken 2 2,977 Jan-11-2018, 10:30 AM
Last Post: StoopidChicken
  Discord bot that asks questions and based on response answers or asks more questions absinthium 1 41,947 Nov-25-2017, 06:21 AM
Last Post: heiner55
  changing variable outside of a function tkj80 8 7,234 Jan-05-2017, 03:52 AM
Last Post: tkj80

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020