关于系统的见解错误:com峎backpatch:偏移量太大

2024-10-03 06:18:36 发布

您现在位置:Python中文网/ 问答频道 /正文

在python中,"SystemError: com_backpatch: offset too large"在执行由以下内容生成的代码时抛出:

f = open("test.py", "w")
f.write("def fn():\n   a =1000\n")
for a in xrange(3000):
   if a == 0:
      f.write("   if a == "+str(a)+": \n      print  "+str(a)+"\n")
   else:
      f.write("   elif a == "+str(a)+": \n      print  "+str(a)+"\n")



f.close()

import test

很明显,如果length语句超出了某个长度,就会抛出这个错误。在

有人能对这个错误有更深入的了解吗?在


Tags: 代码pytestcomif错误openoffset
3条回答

看起来你已经达到了python解释器的限制。从if开始到结束的分支似乎太远了,可能是因为偏移量被限制在16位。如果将“elif”改为“If”,那么问题就消失了。在

您需要减小“if/elif”链的大小。在

……里奇

JFYI,这个脚本在一个有32位用户空间、内核和python2.5.4的Debian测试主机上工作。在

$ ls -ln
total 4
-rw-r r  1 1000 1000 270 2009-12-23 02:53 gentest.py
$ python gentest.py 
$ ls -ln
total 216
-rw-r r  1 1000 1000    270 2009-12-23 02:53 gentest.py
-rw-r r  1 1000 1000 111799 2009-12-23 02:58 test.py
-rw-r r  1 1000 1000  93299 2009-12-23 02:58 test.pyc
$ uname -srvmo
Linux 2.6.30-2-486 #1 Thu Dec 3 23:32:25 UTC 2009 i686 GNU/Linux
$ python  version
Python 2.5.4

据此:http://www.cgl.ucsf.edu/pipermail/chimera-dev/2007/000404.html

The Python bytecode compiler has a limitation of a maximum of a 16 bit offset in a jump instruction. This means that you don't want to have 64K worth of characters in a single conditional block of code

更多详细信息:http://www.mail-archive.com/python-list@python.org/msg72631.html

相关问题 更多 >