Passing information between modules

Tobiah toby at tobiah.org
Fri Nov 18 10:19:42 EST 2022


On 11/18/22 02:53, Stefan Ram wrote:
>    Can I use "sys.argv" to pass information between modules
>    as follows?
> 
>    in module A:
> 
> import sys
> sys.argv.append( "Hi there!" )
> 
>    in module B:
> 
> import sys
> message = sys.argv[ -1 ]

Kind of seems like a code smell.  I think you would normally
just inject the dependencies like:

	module_b.do_thing("Hi there!")

If you really want to have a module-global space,
you could just create a module globals.py, and
import that in every module that needs to share globals.
You can just do globals.message = "Hi there!" and
from another module do print globals.message.








More information about the Python-list mailing list