如何清空python的变量
https://www.jb51.net/article/190126.htm
1、脚本内容如下:
1
2
3
4
5
6
7
8
|
#删除clear_env.py = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = def __clear_env(): for key in globals ().keys(): if not key.startswith( "__" ): # 排除系统内建函数 globals ().pop(key) = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = |
2、使用方法:拷贝脚本到d:/ 下
import sys
sys.path.append(<<SPAN style="LINE-HEIGHT: 18px; FONT-FAMILY: 宋体, 'Lucida Grande', 'Lucida sans', Verdana, Arial, sans-serif; FONT-SIZE: 13px">clear_env.py所在目录名>) #添加clear_env.py所在目录到python系统路径列表中
import clear_env #导入clear_env.py模块
clear_env.__clear_env() #执行模块函数__clear_env()清楚自定义变量
ok了,南无阿弥陀佛,搞定。如果你嫌麻烦可以在python命令行直接输入如下代码即可:
1
2
3
|
for key in globals ().keys(): if not key.startswith( "__" ): globals ().pop(key) |