Project-wide variable...
Terry Reedy
tjreedy at udel.edu
Fri Jun 24 02:27:17 EDT 2011
On 6/23/2011 11:49 PM, Gnarlodious wrote:
> Let me restate my question.
> Say I have a script Executable.py that calls all other scripts and
> controls them:
>
> #!/usr/local/bin/python
> from Module import Data
> import ModuleTest
>
> ModuleTest.py has this:
>
> print(Data.Plist.Structure)
>
> Running Executable.py gives me this:
> NameError: name 'Data' is not defined
>
> 1) Can I tell Executable.py to share Data with ModuleTest.py?
After the import is complete, yes.
import ModuleTest
ModuleTest.Data = Data
This works if the use of Data is inside a function that is not called
during import, not if the use of Data is at toplevel or in a class
statement outside a def.
> or if that can't be done:
> 2) Can I tell ModuleTest.py to "look upstream" for Data?
Yes if ModuleTest imports Executable, but circular imports are a bad idea.
--
Terry Jan Reedy
More information about the Python-list
mailing list