python3 动态模块导入与全局变量使用实例
时间: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;
}
上一篇:解决win64 Python下安装PIL出错问题(图解)
栏 目:Python代码
下一篇:python paramiko实现ssh远程访问的方法
本文地址:http://www.codeinn.net/misctech/40710.html






