0

I'm working on a program where for the sake of keeping it organized, I have a main script, call it main.py, then each of my sub scripts in their various files, call them extra1.py and extra2.py

My main script looks like this...

#!/usr/bin/env python

import extra1
import extra2

If I want to access something from extra1 I can do so by pre-appending "extra1.". This is great, but what if I want to access something in main.py from extra1.py? For example, say in main.py, I have some global variables, how would I access those in extra1.py or extra2.py?

And is it possible for extra1.py to access anything from extra2.py? I've been treating this a lot like PHP's include(), but I'm starting to see that was an incorrect assumption.

halfer
  • 19,824
  • 17
  • 99
  • 186
John Sly
  • 763
  • 1
  • 10
  • 31
  • If I understand this correctly, you are getting into circular dependencies. If you try to import from main into extra{1,2} and extra {1,2} imports from main, you will get an `ImportError` in Python because A cannot depend on B which depends on A. Instead you will have to refactor your program so that both can depend on a third file which contains what you need to import. – Two-Bit Alchemist Aug 24 '16 at 19:16
  • Possible duplicate of [Handle circular dependencies in Python modules?](http://stackoverflow.com/questions/10113383/handle-circular-dependencies-in-python-modules) – Two-Bit Alchemist Aug 24 '16 at 19:17

0 Answers0