Passing information between modules

Thomas Passin list1 at tompassin.net
Sat Nov 19 16:28:43 EST 2022


On 11/19/2022 3:46 PM, Michael F. Stemper wrote:
> On 18/11/2022 04.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 ]
> 
> I just tried and it appears that one can append to sys.argv. However,
> it seems like an incredibly bad idea.

For that matter, you can just directly add attributes to the sys module, 
no need to use sys.argv:

 >>> import sys
 >>> sys._extra = 'spam'   # Not an exception
 >>> print(sys._extra)
spam

Probably not the best idea, though.  Better to use some module that you 
control directly.




More information about the Python-list mailing list