本文整理汇总了Python中inspect.getcomments方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.getcomments方法的具体用法?Python inspect.getcomments怎么用?Python inspect.getcomments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inspect
的用法示例。
在下文中一共展示了inspect.getcomments方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getdoc
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getcomments [as 别名]
def getdoc(object):
"""Get the doc string or comments for an object."""
result = inspect.getdoc(object) or inspect.getcomments(object)
return result and re.sub('^ *\n', '', result.rstrip()) or ''
示例2: getdoc
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getcomments [as 别名]
def getdoc(object):
"""Get the doc string or comments for an object."""
result = inspect.getdoc(object) or inspect.getcomments(object)
return result and re.sub('^ *\n', '', rstrip(result)) or ''
示例3: getdoc
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getcomments [as 别名]
def getdoc(object):
"""Get the doc string or comments for an object."""
result = inspect.getdoc(object) or inspect.getcomments(object)
result = _encode(result)
return result and re.sub('^ *\n', '', rstrip(result)) or ''
示例4: test_getcomments
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getcomments [as 别名]
def test_getcomments(self):
self.assertEqual(inspect.getcomments(mod), '# line 1\n')
self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n')
示例5: get_doc
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getcomments [as 别名]
def get_doc(obj):
"""Get the doc string or comments for an object.
:param object: object
:returns: doc string
:rtype: str
>>> get_doc(abs)
'abs(number) -> number\\n\\nReturn the absolute value of the argument.'
"""
result = inspect.getdoc(obj) or inspect.getcomments(obj)
return result and RE_EMPTY_LINE.sub('', result.rstrip()) or ''
示例6: test_getcomments
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getcomments [as 别名]
def test_getcomments(self):
self.assertEqual(inspect.getcomments(mod), '# line 1\n')
self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n')
# If the object source file is not available, return None.
co = compile('x=1', '_non_existing_filename.py', 'exec')
self.assertIsNone(inspect.getcomments(co))
# If the object has been defined in C, return None.
self.assertIsNone(inspect.getcomments(list))
示例7: get_object_comments
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getcomments [as 别名]
def get_object_comments(obj):
return inspect.getcomments(obj)