1

I have two files. main.py that has main program logic and functions.py that has additional functions. Lets say main.py has this code

import functions
some_var = 'some value'

I would like to print out value of some_var in my functions.py file. How can I achieve this.

1 Answers1

2

In general, you can do this my simply importing the main module within functions.py

Within your functions.py file:

import main
print main.some_var

However, you currently have a circular dependency problem. See Circular (or cyclic) imports in Python

You could put some_var into a third module, let's say constants.py and then main.py would look like:

import functions
from constants import some_var
... etc

and functions.py would be:

from constants import some_var

Solving your circular dependency problem.

Community
  • 1
  • 1
awesomo
  • 8,526
  • 2
  • 21
  • 24