本文整理匯總了Python中inspect.formatargvalues方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.formatargvalues方法的具體用法?Python inspect.formatargvalues怎麽用?Python inspect.formatargvalues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類inspect
的用法示例。
在下文中一共展示了inspect.formatargvalues方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: format_signature
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def format_signature(func, *args, **kwargs):
# XXX: Should this use inspect.formatargvalues/formatargspec?
module, name = get_func_name(func)
module = [m for m in module if m]
if module:
module.append(name)
module_path = '.'.join(module)
else:
module_path = name
arg_str = list()
previous_length = 0
for arg in args:
formatted_arg = _format_arg(arg)
if previous_length > 80:
formatted_arg = '\n%s' % formatted_arg
previous_length = len(formatted_arg)
arg_str.append(formatted_arg)
arg_str.extend(['%s=%s' % (v, _format_arg(i)) for v, i in kwargs.items()])
arg_str = ', '.join(arg_str)
signature = '%s(%s)' % (name, arg_str)
return module_path, signature
示例2: format_signature
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def format_signature(func, *args, **kwargs):
# XXX: Should this use inspect.formatargvalues/formatargspec?
module, name = get_func_name(func)
module = [m for m in module if m]
if module:
module.append(name)
module_path = '.'.join(module)
else:
module_path = name
arg_str = list()
previous_length = 0
for arg in args:
arg = pformat(arg, indent=2)
if len(arg) > 1500:
arg = '%s...' % arg[:700]
if previous_length > 80:
arg = '\n%s' % arg
previous_length = len(arg)
arg_str.append(arg)
arg_str.extend(['%s=%s' % (v, pformat(i)) for v, i in kwargs.items()])
arg_str = ', '.join(arg_str)
signature = '%s(%s)' % (name, arg_str)
return module_path, signature
示例3: test_frame
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def test_frame(self):
args, varargs, varkw, locals = inspect.getargvalues(mod.fr)
self.assertEqual(args, ['x', 'y'])
self.assertEqual(varargs, None)
self.assertEqual(varkw, None)
self.assertEqual(locals, {'x': 11, 'p': 11, 'y': 14})
self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals),
'(x=11, y=14)')
示例4: test_previous_frame
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def test_previous_frame(self):
args, varargs, varkw, locals = inspect.getargvalues(mod.fr.f_back)
self.assertEqual(args, ['a', 'b', 'c', 'd', ['e', ['f']]])
self.assertEqual(varargs, 'g')
self.assertEqual(varkw, 'h')
self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals),
'(a=7, b=8, c=9, d=3, (e=4, (f=5,)), *g=(), **h={})')
示例5: test_previous_frame
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def test_previous_frame(self):
args, varargs, varkw, locals = inspect.getargvalues(mod.fr.f_back)
self.assertEqual(args, ['a', 'b', 'c', 'd', 'e', 'f'])
self.assertEqual(varargs, 'g')
self.assertEqual(varkw, 'h')
self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals),
'(a=7, b=8, c=9, d=3, e=4, f=5, *g=(), **h={})')
示例6: _get_call_info
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def _get_call_info(level):
"""
輸出調用日誌打印的函數的函數名及形參、實參。僅當配置的日誌打印級別為DEBUG時的情況下才會輸出這些詳細信息
"""
frames = inspect.stack()
fr = frames[4][0]
args_pretty = inspect.formatargvalues(*(inspect.getargvalues(fr)), formatvalue=Logger._formatvalue)
filename, lineno, funcname, _, _ = inspect.getframeinfo(fr, -1)
filename = filename.split('/')[-1]
if level != logging.DEBUG and funcname != "<module>":
return '%s:%d/%s%s' % (filename, lineno, funcname, args_pretty)
else:
return '%s:%d/%s' % (filename, lineno, funcname)
示例7: test_frame
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def test_frame(self):
args, varargs, varkw, locals = inspect.getargvalues(mod.fr)
self.assertEqual(args, ['x', 'y'])
self.assertEqual(varargs, None)
self.assertEqual(varkw, None)
self.assertEqual(locals, {'x': 11, 'p': 11, 'y': 14})
self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals),
'(x=11, y=14)')
# TODO - test_previous_frame could be rewritten such that we could
# introspect on the previous frame but without a dependency on
# tuple unpacking
示例8: GetMyRepresentation
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def GetMyRepresentation(value):
"""
Give a shorter representation of some wx-objects. Returns normal repr()
for everything else. Also adds a "=" sign at the beginning to make it
useful as a "formatvalue" function for inspect.formatargvalues().
"""
typeString = repr(type(value))
if typeString.startswith("<class 'wx._core."):
return "=<wx.%s>" % typeString[len("<class 'wx._core."): -2]
if typeString.startswith("<class 'wx._controls."):
return "=<wx.%s>" % typeString[len("<class 'wx._controls."): -2]
return "=" + repr(value)
示例9: format_signature
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import formatargvalues [as 別名]
def format_signature(self, func, *args, **kwds):
# XXX: This should be moved out to a function
# XXX: Should this use inspect.formatargvalues/formatargspec?
module, name = get_func_name(func)
module = [m for m in module if m]
if module:
module.append(name)
module_path = '.'.join(module)
else:
module_path = name
arg_str = list()
previous_length = 0
for arg in args:
arg = self.format(arg, indent=2)
if len(arg) > 1500:
arg = '%s...' % arg[:700]
if previous_length > 80:
arg = '\n%s' % arg
previous_length = len(arg)
arg_str.append(arg)
arg_str.extend(['%s=%s' % (v, self.format(i)) for v, i in
kwds.iteritems()])
arg_str = ', '.join(arg_str)
signature = '%s(%s)' % (name, arg_str)
return module_path, signature
# Make make public