I'm using python to create my first independent program, It consists of two modules. I am trying to import the main module into the other one, however whenever I import the main module, it runs the entire code. I just want to use attributes and functions from this code, but I'm not quite sure how to. Any help on this matter is greatly appreciated!
Asked
Active
Viewed 13 times
0
-
Importing a module runs all code inside. Ideally this would just be variable/function definitions, but it seems you actually have code running. Of course, we can't help more without a small example of your code here. – clubby789 Jan 23 '20 at 13:21
-
FWIW, [this is explained in the official tutorial](https://docs.python.org/3/tutorial/modules.html#executing-modules-as-scripts). – bruno desthuilliers Jan 23 '20 at 13:36