Importing Variables In Python, New Topic As The Old One Does Not Work For Me
I have read all of the answers of the following link : Importing variables from another file? I have tried what they say, to import my variables from one file to another by tapping
Solution 1:
You most likely have some code running in your file which is either outside of defined functions all together or in a main function that is run automaticalls upon running (and thus also when imported.
In other words if file1 looks like this:
var1 = 'hello'
def printHello():
print var1
then writing from file1 import var1
will only import that. If on the other hand file1 looks like this:
var1 = 'hello'
print var1
It will import var1
but also print 'hello'.
Post a Comment for "Importing Variables In Python, New Topic As The Old One Does Not Work For Me"