Jun-04-2018, 08:45 AM
Please don't send private messages. The forum is for all to learn from.
I am re-posting your pm here:
............................................
Hi Larz,
Thanks and my problem is that I want to use the variable declared in a function in another python script.
I am able to call the variables declared globally.
r1.py
............................................
You could do this better by using a class:
r1.py
I am re-posting your pm here:
............................................
Hi Larz,
Thanks and my problem is that I want to use the variable declared in a function in another python script.
I am able to call the variables declared globally.
r1.py
def f1(): test = 100r2.py
import r1 a = r1.test print ahere in r1.py I declared a variable "test" and I want to use this in r2.py
............................................
You could do this better by using a class:
r1.py
class r1: def __init__(self): self.test = None def f1(self): self.test = 100r2.py
import r1 # create instance of r1 myr1 = r1.r1() # execute r1 function f1 myr1.f1() # Create new variable a which is equal to myr1.test a = myr1.test + 100 print(a)results:
Output:200