• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pydoc.allmethods函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pydoc.allmethods函数的典型用法代码示例。如果您正苦于以下问题:Python allmethods函数的具体用法?Python allmethods怎么用?Python allmethods使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了allmethods函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_allmethods

    def test_allmethods(self):
        # issue 17476: allmethods was no longer returning unbound methods.
        # This test is a bit fragile in the face of changes to object and type,
        # but I can't think of a better way to do it without duplicating the
        # logic of the function under test.

        class TestClass(object):
            def method_returning_true(self):
                return True

        # What we expect to get back: everything on object...
        expected = dict(vars(object))
        # __new__'s descriptor can be a staticmethod on PyPy
        expected['__new__'] = object.__new__
        # ...plus our unbound method...
        expected['method_returning_true'] = TestClass.method_returning_true
        # ...but not the non-methods on object.
        del expected['__doc__']
        del expected['__class__']
        # inspect resolves descriptors on type into methods, but vars doesn't,
        # so we need to update __subclasshook__.
        expected['__subclasshook__'] = TestClass.__subclasshook__

        methods = pydoc.allmethods(TestClass)
        self.assertDictEqual(methods, expected)
开发者ID:Qointum,项目名称:pypy,代码行数:25,代码来源:test_pydoc.py


示例2: docclass

    def docclass(self, object, name=None, mod=None):
        ''' Produce text documentation for a given class object.
        '''
        realname = object.__name__
        name = name or realname
        bases = object.__bases__

        if name == realname:
            title = '### class ' + self.bold(realname)
        else:
            title = '### ' + self.bold(name) + ' = class ' + realname
        if bases:
            def makename(c, m=object.__module__): return pydoc.classname(c, m)
            parents = map(makename, bases)
            title = title + '(%s)' % ', '.join(parents)

        doc = pydoc.getdoc(object)
        contents = doc and doc + '\n'
        methods = pydoc.allmethods(object).items()
        methods.sort()
        for key, value in methods:
            if key.startswith('_'):
                continue    
            contents = contents + '\n' + self.document(value, key, mod, object)

        if not contents: return title + '\n'
        return title + '\n' + self.indent(contents.rstrip()) + '\n'
开发者ID:ownport,项目名称:pydoc2md,代码行数:27,代码来源:pydoc2md.py


示例3: usage

def usage(obj, selfname='self'):
    str(obj) # In case it's lazy, this will load it.

    if not isinstance(obj, class_types):
        obj = obj.__class__

    print('%s supports the following operations:' % obj.__name__)
    for (name, method) in sorted(pydoc.allmethods(obj).items()):
        if name.startswith('_'): continue
        if getattr(method, '__deprecated__', False): continue

        if sys.version_info[0] >= 3:
            getargspec = inspect.getfullargspec
        else:
            getargspec = inspect.getargspec
        args, varargs, varkw, defaults = getargspec(method)[:4]
        if (args and args[0]=='self' and
            (defaults is None or len(args)>len(defaults))):
            args = args[1:]
            name = '%s.%s' % (selfname, name)
        argspec = inspect.formatargspec(
            args, varargs, varkw, defaults)
        print(textwrap.fill('%s%s' % (name, argspec),
                            initial_indent='  - ',
                            subsequent_indent=' '*(len(name)+5)))
开发者ID:Weiming-Hu,项目名称:text-based-six-degree,代码行数:25,代码来源:util.py


示例4: _print_help

 def _print_help(self, a, level=0):
     if isinstance(a, PhycasCommand):
         a.help()
     elif isinstance(a, PhycasCommandOutputOptions):
         print (str(a))
     elif a is None:
         print("None is the Python object used to represent the concept 'undefined' or 'not applicable'")
     elif a is True:
         print("True is the Python's representation of the boolean condition 'true'.")
     elif a is False:
         print("False is the Python's representation of the boolean condition 'false'.")
     elif isinstance(a, int) or isinstance(a, long):
         print("The integer", str(a))
     elif isinstance(a, float):
         print("The real number", str(a))
     elif isinstance(a, str):
         print("The string %s\nIf you would like to see the methods available for a string use the command 'help(str)'" % repr(a))
     elif isinstance(a, list):
         print("A python list. Use [number] to access elements in the list. For instance, x[0] is the first element of list x.\nUse 'help(list)' to see a list of available methods")
     elif isinstance(a, list):
         print("A python tuple. Use [number] to access elements in the list. For instance, x[0] is the first element of tuple x.\nUse 'help(tuple)' to see a list of available methods")
     elif isinstance(a, dict):
         print("A python dict. Use [key] to access elements in the list. For instance, x[2] returns the value associated with the key 2 (if there is such an element in the dictionary).\nUse 'help(dict)' to see a list of available methods")
     else:
         import pydoc
         d = pydoc.getdoc(a)
         if isinstance(a, type):
             m = pydoc.allmethods(a)
             pub_methods = [k for k in m.iterkeys() if not k.startswith("_")]
             if pub_methods or d:
                 if level == 0:
                     print("\nThis is a class or python type")
                 else:
                     print("Information about this type:")
                 if d:
                     print(d)
                 if pub_methods:
                     print("\nThe following public methods are available:\n%s" % '\n'.join(pub_methods))
             else:
                 print("\nThis is an undocumented class or python type without public methods")
         else:
             print("\n%s\n\nAn instance of type %s.\n" % (repr(a), a.__class__.__name__))
             if callable(a):
                 if d:
                     print(d)
             else:
                 self._print_help(a.__class__, level+1)
开发者ID:danielfan,项目名称:Phycas,代码行数:47,代码来源:PhycasCommand.py


示例5: usage

def usage(obj, selfname="self"):
    import inspect

    str(obj)  # In case it's lazy, this will load it.

    if not isinstance(obj, class_types):
        obj = obj.__class__

    print("%s supports the following operations:" % obj.__name__)
    for (name, method) in sorted(pydoc.allmethods(obj).items()):
        if name.startswith("_"):
            continue
        if getattr(method, "__deprecated__", False):
            continue

        args, varargs, varkw, defaults = inspect.getargspec(method)
        if args and args[0] == "self" and (defaults is None or len(args) > len(defaults)):
            args = args[1:]
            name = "%s.%s" % (selfname, name)
        argspec = inspect.formatargspec(args, varargs, varkw, defaults)
        print(textwrap.fill("%s%s" % (name, argspec), initial_indent="  - ", subsequent_indent=" " * (len(name) + 5)))
开发者ID:Reagankm,项目名称:KnockKnock,代码行数:21,代码来源:util.py


示例6: info


#.........这里部分代码省略.........

    elif inspect.isfunction(object):
        name = object.func_name
        arguments = inspect.formatargspec(*inspect.getargspec(object))

        if len(name+arguments) > maxwidth:
            argstr = _split_line(name, arguments, maxwidth)
        else:
            argstr = name + arguments

        print >> output, " " + argstr + "\n"
        print >> output, inspect.getdoc(object)

    elif inspect.isclass(object):
        name = object.__name__
        arguments = "()"
        try:
            if hasattr(object, '__init__'):
                arguments = inspect.formatargspec(*inspect.getargspec(object.__init__.im_func))
                arglist = arguments.split(', ')
                if len(arglist) > 1:
                    arglist[1] = "("+arglist[1]
                    arguments = ", ".join(arglist[1:])
        except:
            pass

        if len(name+arguments) > maxwidth:
            argstr = _split_line(name, arguments, maxwidth)
        else:
            argstr = name + arguments

        print >> output, " " + argstr + "\n"
        doc1 = inspect.getdoc(object)
        if doc1 is None:
            if hasattr(object,'__init__'):
                print >> output, inspect.getdoc(object.__init__)
        else:
            print >> output, inspect.getdoc(object)

        methods = pydoc.allmethods(object)
        if methods != []:
            print >> output, "\n\nMethods:\n"
            for meth in methods:
                if meth[0] == '_':
                    continue
                thisobj = getattr(object, meth, None)
                if thisobj is not None:
                    methstr, other = pydoc.splitdoc(inspect.getdoc(thisobj) or "None")
                print >> output, "  %s  --  %s" % (meth, methstr)

    elif type(object) is types.InstanceType: ## check for __call__ method
        print >> output, "Instance of class: ", object.__class__.__name__
        print >> output
        if hasattr(object, '__call__'):
            arguments = inspect.formatargspec(*inspect.getargspec(object.__call__.im_func))
            arglist = arguments.split(', ')
            if len(arglist) > 1:
                arglist[1] = "("+arglist[1]
                arguments = ", ".join(arglist[1:])
            else:
                arguments = "()"

            if hasattr(object,'name'):
                name = "%s" % object.name
            else:
                name = "<name>"
            if len(name+arguments) > maxwidth:
                argstr = _split_line(name, arguments, maxwidth)
            else:
                argstr = name + arguments

            print >> output, " " + argstr + "\n"
            doc = inspect.getdoc(object.__call__)
            if doc is not None:
                print >> output, inspect.getdoc(object.__call__)
            print >> output, inspect.getdoc(object)

        else:
            print >> output, inspect.getdoc(object)

    elif inspect.ismethod(object):
        name = object.__name__
        arguments = inspect.formatargspec(*inspect.getargspec(object.im_func))
        arglist = arguments.split(', ')
        if len(arglist) > 1:
            arglist[1] = "("+arglist[1]
            arguments = ", ".join(arglist[1:])
        else:
            arguments = "()"

        if len(name+arguments) > maxwidth:
            argstr = _split_line(name, arguments, maxwidth)
        else:
            argstr = name + arguments

        print >> output, " " + argstr + "\n"
        print >> output, inspect.getdoc(object)

    elif hasattr(object, '__doc__'):
        print >> output, inspect.getdoc(object)
开发者ID:AndreI11,项目名称:SatStressGui,代码行数:101,代码来源:utils.py


示例7: info


#.........这里部分代码省略.........

    elif inspect.isfunction(object):
        name = object.func_name
        arguments = inspect.formatargspec(*inspect.getargspec(object))

        if len(name+arguments) > maxwidth:
            argstr = _split_line(name, arguments, maxwidth)
        else:
            argstr = name + arguments

        print >> output, " " + argstr + "\n"
        print >> output, inspect.getdoc(object)

    elif inspect.isclass(object):
        name = object.__name__
        arguments = "()"
        try:
            if hasattr(object, '__init__'):
                arguments = inspect.formatargspec(*inspect.getargspec(object.__init__.im_func))
                arglist = arguments.split(', ')
                if len(arglist) > 1:
                    arglist[1] = "("+arglist[1]
                    arguments = ", ".join(arglist[1:])
        except:
            pass

        if len(name+arguments) > maxwidth:
            argstr = _split_line(name, arguments, maxwidth)
        else:
            argstr = name + arguments

        print >> output, " " + argstr + "\n"
        doc1 = inspect.getdoc(object)
        if doc1 is None:
            if hasattr(object,'__init__'):
                print >> output, inspect.getdoc(object.__init__)
        else:
            print >> output, inspect.getdoc(object)

        methods = pydoc.allmethods(object)
        if methods != []:
            print >> output, "\n\nMethods:\n"
            for meth in methods:
                if meth[0] == '_':
                    continue
                thisobj = getattr(object, meth, None)
                if thisobj is not None:
                    methstr, other = pydoc.splitdoc(inspect.getdoc(thisobj) or "None")
                print >> output, "  %s  --  %s" % (meth, methstr)

    elif type(object) is types.InstanceType: ## check for __call__ method
        print >> output, "Instance of class: ", object.__class__.__name__
        print >> output
        if hasattr(object, '__call__'):
            arguments = inspect.formatargspec(*inspect.getargspec(object.__call__.im_func))
            arglist = arguments.split(', ')
            if len(arglist) > 1:
                arglist[1] = "("+arglist[1]
                arguments = ", ".join(arglist[1:])
            else:
                arguments = "()"

            if hasattr(object,'name'):
                name = "%s" % object.name
            else:
                name = "<name>"
            if len(name+arguments) > maxwidth:
                argstr = _split_line(name, arguments, maxwidth)
            else:
                argstr = name + arguments

            print >> output, " " + argstr + "\n"
            doc = inspect.getdoc(object.__call__)
            if doc is not None:
                print >> output, inspect.getdoc(object.__call__)
            print >> output, inspect.getdoc(object)

        else:
            print >> output, inspect.getdoc(object)

    elif inspect.ismethod(object):
        name = object.__name__
        arguments = inspect.formatargspec(*inspect.getargspec(object.im_func))
        arglist = arguments.split(', ')
        if len(arglist) > 1:
            arglist[1] = "("+arglist[1]
            arguments = ", ".join(arglist[1:])
        else:
            arguments = "()"

        if len(name+arguments) > maxwidth:
            argstr = _split_line(name, arguments, maxwidth)
        else:
            argstr = name + arguments

        print >> output, " " + argstr + "\n"
        print >> output, inspect.getdoc(object)

    elif hasattr(object, '__doc__'):
        print >> output, inspect.getdoc(object)
开发者ID:1950,项目名称:sawbuck,代码行数:101,代码来源:utils.py


示例8: info

def info(object=None, maxwidth=76, output=sys.stdout):
    """Get help information for a function, class, or module.

       Example:
          >>> from scipy import *
          >>> info(polyval)
          polyval(p, x)

            Evaluate the polymnomial p at x.

            Description:
                If p is of length N, this function returns the value:
                p[0]*(x**N-1) + p[1]*(x**N-2) + ... + p[N-2]*x + p[N-1]
    """
    global _namedict, _dictlist

    if hasattr(object, "_ppimport_importer") or hasattr(object, "_ppimport_module"):
        object = object._ppimport_module
    elif hasattr(object, "_ppimport_attr"):
        object = object._ppimport_attr

    if object is None:
        info(info)
    elif isinstance(object, types.StringType):
        if _namedict is None:
            _namedict, _dictlist = makenamedict()
        numfound = 0
        objlist = []
        for namestr in _dictlist:
            try:
                obj = _namedict[namestr][object]
                if id(obj) in objlist:
                    print >> output, "\n     *** Repeat reference found in %s *** " % namestr
                else:
                    objlist.append(id(obj))
                    print >> output, "     *** Found in %s ***" % namestr
                    info(obj)
                    print >> output, "-" * maxwidth
                numfound += 1
            except KeyError:
                pass
        if numfound == 0:
            print >> output, "Help for %s not found." % object
        else:
            print >> output, "\n     *** Total of %d references found. ***" % numfound

    elif inspect.isfunction(object):
        name = object.func_name
        arguments = apply(inspect.formatargspec, inspect.getargspec(object))

        if len(name + arguments) > maxwidth:
            argstr = split_line(name, arguments, maxwidth)
        else:
            argstr = name + arguments

        print >> output, " " + argstr + "\n"
        print >> output, inspect.getdoc(object)

    elif inspect.isclass(object):
        name = object.__name__
        if hasattr(object, "__init__"):
            arguments = apply(inspect.formatargspec, inspect.getargspec(object.__init__.im_func))
            arglist = arguments.split(", ")
            if len(arglist) > 1:
                arglist[1] = "(" + arglist[1]
                arguments = ", ".join(arglist[1:])
            else:
                arguments = "()"
        else:
            arguments = "()"

        if len(name + arguments) > maxwidth:
            argstr = split_line(name, arguments, maxwidth)
        else:
            argstr = name + arguments

        print >> output, " " + argstr + "\n"
        doc1 = inspect.getdoc(object)
        if doc1 is None:
            if hasattr(object, "__init__"):
                print >> output, inspect.getdoc(object.__init__)
        else:
            print >> output, inspect.getdoc(object)

        methods = pydoc.allmethods(object)
        if methods != []:
            print >> output, "\n\nMethods:\n"
            for meth in methods:
                if meth[0] == "_":
                    continue
                thisobj = getattr(object, meth, None)
                if thisobj is not None:
                    methstr, other = pydoc.splitdoc(inspect.getdoc(thisobj) or "None")
                print >> output, "  %s  --  %s" % (meth, methstr)

    elif type(object) is types.InstanceType:  ## check for __call__ method
        print >> output, "Instance of class: ", object.__class__.__name__
        print >> output
        if hasattr(object, "__call__"):
            arguments = apply(inspect.formatargspec, inspect.getargspec(object.__call__.im_func))
#.........这里部分代码省略.........
开发者ID:qsnake,项目名称:scipy,代码行数:101,代码来源:helpmod.py



注:本文中的pydoc.allmethods函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pydoc.apropos函数代码示例发布时间:2022-05-25
下一篇:
Python config.DnstestConfig类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap