本文整理匯總了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)