+ 1

Import Variable From Another Script

I have two scripts. I am trying to import everything from Script2 into Script1. Functions. variables, lists, dictionary's, etc. Script1: import script2 if x==5: print("ABC") Script2: x=5 The output should be "ABC" but all I get is an error.

10th May 2017, 2:05 AM
MemeSenpai
MemeSenpai - avatar
1 Respuesta
- 1
access through Script2.x or 'from Script2 import x' start using a decent IDE and it will point out these things among many more edit: you can for example, do 'from math import *'. but it is always a bad idea. for one, a newcomer who reads your sources will be clueless as to whether the sqrt is defined by you elsewhere in the project or it is indeed the sqrt from math. another problem is potential for name collision increases. so most Python developers use math.sqrt way of referring to imported module's methods.
10th May 2017, 2:30 AM
Venkatesh Pitta
Venkatesh Pitta - avatar