# 需要导入模块: import code [as 别名]

# 或者: from code import co_consts [as 别名]

def get_generic_cmd(obj, ui, cliclass=GenericCLI, aliases=None, gbl=None):

"""get a GenericCLI (or other) command set wrapping any class instance

object. The wrapped objects public methods have CLI command counterparts

automatically created."""

import new

from pycopia.methodholder import MethodHolder

cmd = cliclass(ui, aliases)

if gbl is None:

gbl = globals()

hashfilter = {}

for name in _get_methodnames(obj):

if hasattr(cmd, name):

continue # don't override already defined methods

# all this mess does is introspect the object methods and map it to a CLI

# object method of the same name, with a docstring showing the attributes

# and their default values, and the actual code mirroring the

# _generic_call method in the GenericCLI class.

else:

obj_meth = getattr(obj, name)

if id(obj_meth.__func__) in hashfilter: # filter out aliases

continue

else:

hashfilter[id(obj_meth.__func__)] = True

mh = MethodHolder(obj_meth)

doc = "%s *\n%s" % (mh, obj_meth.__doc__ or "")

code = cliclass._generic_call.func_code

nc = new.code(code.co_argcount, code.co_nlocals, code.co_stacksize,

code.co_flags, code.co_code,

(doc,)+code.co_consts[1:], # replace docstring

code.co_names, code.co_varnames, code.co_filename,

code.co_name, code.co_firstlineno, code.co_lnotab)

f = new.function(nc, gbl, name)

m = new.instancemethod(f, cmd, cliclass)

setattr(cmd, name, m)

cmd._setup(obj, "Object:%s> " % (obj.__class__.__name__,))

return cmd

python codefirst_Python code.co_consts方法代码示例相关推荐

  1. python paperclip_Python pyplot.sca方法代码示例

    本文整理汇总了Python中matplotlib.pyplot.sca方法的典型用法代码示例.如果您正苦于以下问题:Python pyplot.sca方法的具体用法?Python pyplot.sca ...

  2. python descript_Python descriptor.FieldDescriptor方法代码示例

    本文整理汇总了Python中google.protobuf.descriptor.FieldDescriptor方法的典型用法代码示例.如果您正苦于以下问题:Python descriptor.Fie ...

  3. python dateformatter_Python dates.DateFormatter方法代码示例

    本文整理汇总了Python中matplotlib.dates.DateFormatter方法的典型用法代码示例.如果您正苦于以下问题:Python dates.DateFormatter方法的具体用法 ...

  4. python fonttool_Python wx.Font方法代码示例

    本文整理汇总了Python中wx.Font方法的典型用法代码示例.如果您正苦于以下问题:Python wx.Font方法的具体用法?Python wx.Font怎么用?Python wx.Font使用 ...

  5. python res_Python models.resnet152方法代码示例

    本文整理汇总了Python中torchvision.models.resnet152方法的典型用法代码示例.如果您正苦于以下问题:Python models.resnet152方法的具体用法?Pyth ...

  6. python dropout_Python slim.dropout方法代码示例

    本文整理汇总了Python中tensorflow.contrib.slim.dropout方法的典型用法代码示例.如果您正苦于以下问题:Python slim.dropout方法的具体用法?Pytho ...

  7. python batch_size_Python config.batch_size方法代码示例

    本文整理汇总了Python中config.batch_size方法的典型用法代码示例.如果您正苦于以下问题:Python config.batch_size方法的具体用法?Python config. ...

  8. python pool_Python pool.Pool方法代码示例

    本文整理汇总了Python中multiprocessing.pool.Pool方法的典型用法代码示例.如果您正苦于以下问题:Python pool.Pool方法的具体用法?Python pool.Po ...

  9. python nextpow2_Python signal.hann方法代码示例

    本文整理汇总了Python中scipy.signal.hann方法的典型用法代码示例.如果您正苦于以下问题:Python signal.hann方法的具体用法?Python signal.hann怎么 ...

最新文章

  1. IDEA搭建Maven Web(SSM)项目(一)——创建项目
  2. SVD理论以及Python实现
  3. The Road to SDN: An Intellectual History of Programmable Networks
  4. 为什么我们应该担心华尔街的人工智能
  5. 顶尖学府 加州伯克利大学开发高效机器人操纵框架
  6. CODE[VS] 1346 HelloWorld编译器
  7. Spring AOP 源码初窥(二) 从注解开始
  8. 相对于其他框架的离子应用开发:它被炒作了吗?
  9. error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 E:\OCX
  10. 买车,给点建议和意见
  11. 电源大师课笔记 3.3
  12. 时间计算题100道_史上最全50道初中数学几何必刷题(上)
  13. 怎么打开linux的超级终端,电脑超级终端在哪里|电脑打开超级终端的方法
  14. 多校HDU.5724 Chess
  15. 数学不好 学软件测试能学会吗,英语差、数学烂,我还能学好编程吗?
  16. oracle版linux查看rac ip,oracle10g RAC中查看Private IP的方法
  17. R文本挖掘-文章关键词提取
  18. 如何获得ADI公司的技术支持服务
  19. CentOS 6 64 安装
  20. Python Mac 1

热门文章

  1. python元组和列表的联系_Python | 一文看懂Python列表、元组和字符串操作
  2. Deferred Shading,延迟渲染(提高渲染效率,减少多余光照计算)
  3. 不会点SQLite,都不好意思说自己是开发的
  4. windows 2008 r2 AD域控服务器部署
  5. [转]:tbox中数据库的使用
  6. 修改eclipse配置文件properties编码格式
  7. glibc库详解及与POSIX,system V这些库之间关系的说明
  8. 微信快速开发框架(二) -- 快速开发微信公众平台框架---简介
  9. PHP正则表达式学习(一) 模式修正符
  10. RHEL6 安装ipvsadm-1.26