打印出python 当前全局变量和入口参数的所有属性
时间:2022-09-01 07:06:51
def cndebug(obj=False):
"""
Author : Nemon
Update : 2009.7.1
TO use : cndebug(obj) or cndebug() or MyObject.debug=cndebug
License: GPL
"""
print('='*80)
print('='*30 + ' GLOBAL VARIABLES ' +'='*30)
print('='*80)
g=globals()
for x,y in g.iteritems():
if x[:1]!='_':
print ( x + ' := '+ str(type(y)))
print ( y)
print ( '')
if obj:
print('='*80)
print('='*30 + ' LOCAL VARIABLES ' +'='*30)
print('='*80)
for o in dir(obj):
#if o[:1]!='_':
print (o + ' := ' + str(type(getattr(obj,o))))
print ( getattr(obj,o))
print ( '')
print('='*80)
o=raw_input('PRESS <ENTER> TO RESUME...')
del x,y,o
简单用法:
1)打印出python 当前全局变量
cndebug()#
2)打印出当前全局变量和myobj的所有属性
myobj={}
cndebug(myobj)
扩展用法——当作类方法,打印实例的成员
>>> class MyObj():
... debug=cndebug
...
>>> myObj1=MyObj()
>>> myObj1.debug()
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Oracle 存储过程加密方法
php中Ctype函数用法详解
SQL Server日志清除的两种方法教程简介
给验证码增加干扰的杂点
利用Yahoo Pipes和jQuery做一个RSS挂件
ASP中汉字与UTF-8的互相转换
Python远程linux执行命令实现
Dreamweaver制作技巧四则
Oracle数据库的备份与恢复
精巧支付宝导航条制作教程
解构用户研究
![](https://img.aspxhome.com/file/UploadPic/20103/15/deconstructing_user_research_banner730-250-33s.jpg)
浅谈MySQL存储引擎选择 InnoDB还是MyISAM
在IE下获取object(ActiveX)的Param
二十八法优化SQL Server数据库查询
go slice 数组和切片使用区别示例解析
![](https://img.aspxhome.com/file/2023/0/87610_0s.jpg)
一个典型的PHP分页实例代码分享
ASP强制刷新和判断文件地址是否存在
golang基于websocket实现的简易聊天室程序
apache集成php7.3.5的详细步骤
![](https://img.aspxhome.com/file/2023/9/55479_0s.png)