How to make a variable's late binding crosses the module boundary?

Jach Feng jfong at ms4.hinet.net
Sat Aug 27 21:40:18 EDT 2022


Mark Bourne 在 2022年8月27日 星期六晚上7:42:37 [UTC+8] 的信中寫道:
> import test 
> test.x = 4 
> test.foo() 
> 
> -- 
> Mark.
Yes, you are right. But because of I am using "from test import *" which makes the name "test" disappear in the test2 scope, so this is not work.

I solved this problem by moving "x" to a separate config.py file, import it in both test.py and test2.py, and access it using config.x

--Jach


More information about the Python-list mailing list