I have a one python script "sample.py", the below is the code :
#sample.py
if __name__ == '__main__':
a = 10
b = 5
c = a + b
print(c)
Inside another python script "test.py" , I want to import and use the value of variable "c" from sample.py
#test.py
from sample.py import c
d = c
print(d)
But, when I run "test.py", I am facing the below error : ImportError: cannot import name 'c' from 'sample' Please help me here
Change the scope of the variables a and d like this:
Now you can import variable a and c in your test. However, the variable c is still None because the main program is not executed when you run test.py.