Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python cProfile giving';int';对象不可调用错误_Python_Profiler_Cprofile - Fatal编程技术网

python cProfile giving';int';对象不可调用错误

python cProfile giving';int';对象不可调用错误,python,profiler,cprofile,Python,Profiler,Cprofile,以下脚本运行良好: $ python myscript.py 当我尝试使用cProfile评测代码时,如: $ python -m cProfile -s time myscript.py 或 我发现以下错误: Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 121, in _ru

以下脚本运行良好:

$ python myscript.py 
当我尝试使用cProfile评测代码时,如:

$ python -m cProfile -s time myscript.py

我发现以下错误:

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 121, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 190, in <module>
    main()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 183, in main
    run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 36, in run
    result = prof.print_stats(sort)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 81, in print_stats
    pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 92, in __init__
    self.init(arg)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 106, in init
    self.load_stats(arg)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 130, in load_stats
    arg.create_stats()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 92, in create_stats
    self.snapshot_stats()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 106, in snapshot_stats
    callersdicts[id(entry.code)] = callers
TypeError: 'int' object is not callable
回溯(最近一次呼叫最后一次):
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py”,第121行,在运行模块中
“\uuuuu main\uuuuuuuuuuuuuuuuuuuuuuuuu”,fname,loader,pkg\u name)
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py”,第34行,在运行代码中
run_globals中的exec代码
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py”,第190行,在
main()
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py”,主文件第183行
运行('execfile(%r)'(sys.argv[0],)、options.outfile、options.sort)
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py”,第36行,运行中
结果=教授打印统计(排序)
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py”,第81行,在print_stats中
pstats.Stats(self).strip_dirs().sort_Stats(sort).print_Stats()
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py”,第92行,在__
self.init(arg)
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py”,第106行,在init中
self.load_stats(arg)
load_stats中的文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py”,第130行
arg.create_stats()
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py”,第92行,在create_stats中
self.snapshot_stats()
snapshot_stats中的文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py”,第106行
callersdicts[id(entry.code)]=呼叫者
TypeError:“int”对象不可调用
我的脚本在这两种情况下都成功运行,只是在后一种情况下它阻塞了cProfile。我知道这一定是件很琐碎的事情,只是不能确定


请帮我解决。谢谢

您有一个名为
id
的整数变量,它屏蔽了内置函数。这会弄乱
cProfile


重命名您的
id
变量,并且
cProfile
应该可以正常工作。

我尝试过谷歌搜索,我能得到的最接近的链接是它声明了相同的错误,但没有提到任何解决方案。当然,它的
id
把事情搞砸了。我意识到我的错。谢谢again@jerrymouse每个人都会这样
id
甚至在标准库中用作名称,因为它非常方便。不要理会下层选民,这是一个非常好的问题。
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 121, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 190, in <module>
    main()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 183, in main
    run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 36, in run
    result = prof.print_stats(sort)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 81, in print_stats
    pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 92, in __init__
    self.init(arg)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 106, in init
    self.load_stats(arg)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 130, in load_stats
    arg.create_stats()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 92, in create_stats
    self.snapshot_stats()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 106, in snapshot_stats
    callersdicts[id(entry.code)] = callers
TypeError: 'int' object is not callable