python 打印类的属性、方法

打印变量db的类(class):
[root@fuel ~]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from nailgun.db import db
2016-01-28 15:33:57.512 DEBUG [7fa46d13f700] (settings) Looking for settings.yaml package config using old style __file__
2016-01-28 15:33:57.512 DEBUG [7fa46d13f700] (settings) Trying to read config file /usr/lib/python2.6/site-packages/nailgun/settings.yaml
2016-01-28 15:33:57.733 DEBUG [7fa46d13f700] (settings) Trying to read config file /etc/nailgun/settings.yaml
2016-01-28 15:33:57.752 DEBUG [7fa46d13f700] (settings) Trying to read config file /etc/fuel/version.yaml
>>> print db.__class__
<class 'sqlalchemy.orm.scoping.scoped_session'>
>>> print db.__class__.__name__
scoped_session
>>> exit()



# vi a.py
----------------------------------------------------------------
import re
from sqlalchemy.orm.scoping import scoped_session
d = scoped_session.__dict__
for var in d:
    p = re.compile("__.*__")
    m = p.search(var)
    if m == None:
        print "object.%s=%s" % (var, d[var])
----------------------------------------------------------------
# python a.py
object.add_all=<function do at 0x22a8050>
object.no_autoflush=<property object at 0x22a7310>
object.expunge_all=<function do at 0x22a8578>
object.scalar=<function do at 0x22a8938>
object.query=<function do at 0x22a87d0>
object.close_all=<classmethod object at 0x22a9398>
object.add=<function do at 0x22a5f50>
object.rollback=<function do at 0x22a88c0>
object.configure=<function configure at 0x22a5cf8>
object.query_property=<function query_property at 0x22a5d70>
object.is_active=<property object at 0x22a7260>
object.is_modified=<function do at 0x22a86e0>
object.info=<property object at 0x22a7368>
object.execute=<function do at 0x22a8398>
object.expunge=<function do at 0x22a8500>
object.refresh=<function do at 0x22a8848>
object.autoflush=<property object at 0x22a72b8>
object.merge=<function do at 0x22a8758>
object.dirty=<property object at 0x22a7100>
object.begin_nested=<function do at 0x22a8140>
object.delete=<function do at 0x22a8320>
object.remove=<function remove at 0x22a5c80>
object.flush=<function do at 0x22a85f0>
object.close=<function do at 0x22a81b8>
object.new=<property object at 0x22a71b0>
object.begin=<function do at 0x22a80c8>
object.identity_key=<classmethod object at 0x22a9478>
object.deleted=<property object at 0x22a7158>
object.identity_map=<property object at 0x22a7208>
object.expire=<function do at 0x22a8410>
object.object_session=<classmethod object at 0x22a9408>
object.bind=<property object at 0x22a70a8>
object.expire_all=<function do at 0x22a8488>
object.connection=<function do at 0x22a82a8>
object.commit=<function do at 0x22a8230>
object.get_bind=<function do at 0x22a8668>


转载于:https://www.cnblogs.com/endoresu/p/5166494.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值