开发者

Adding an object to another module's globals in python

开发者 https://www.devze.com 2022-12-22 03:20 出处:网络
I know this is very evil, but is it possible to add an object to anoth开发者_运维知识库er module\'s globals, something like:

I know this is very evil, but is it possible to add an object to anoth开发者_运维知识库er module's globals, something like:

#module dog.py
import cat
cat.globals.addVar('name','mittens')

and

#module cat.py
print name #mittens


setattr(cat, 'name', 'mittens')

or

cat.name = 'mittens'
0

精彩评论

暂无评论...
验证码 换一张
取 消