Aug-23-2017, 07:04 PM
If you use the
if __name__ == "__main__":
check, you should be able to just import it.# eggs.py frame_data = 42 if __name__ == "__main__": import spam print(spam.other_data) print(frame_data) # what will this be?
# spam.py import eggs other_data = eggs.frame_data * 2 eggs.frame_data = 1
Output:> python eggs.py
84
42
It's not a great way to do it, since each module would then have it's own concept of what the values are, so a change in one file won't be reflected in the other (as demonstrated). It works for basic cases, but you're better off restructuring if you want something that works better.