时间:2021-01-05 13:45:38 | 栏目:Python代码 | 点击:次
动态导入有两种:
1 __main__():
f="demo.A" aa=__main__(f) aa.A.t()
2 import importlib:
import importlib f="demo.A" aa=importlib.import_module(f) aa.t()
全局变量使用:
global_list.py: size=None A.py: from demo import global_list global_list.size=101 from demo.B import * t() B.py: from demo import global_list def t(): global_list.size+=100 print(global_list.size)
类似的php
A.php: $size=101 include_once "./B.php" t(); echo $size; B.php: function t(){ global $size; $size+=100; echo $size; }