本文整理汇总了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