如果您想了解使用列表时出现“RuntimeError:最大递归深度超出cmp”和最大递归深度超过比较的知识,那么本篇文章将是您的不二之选。我们将深入剖析使用列表时出现“RuntimeError:最大递
如果您想了解使用列表时出现“ RuntimeError:最大递归深度超出cmp”和最大递归深度超过比较的知识,那么本篇文章将是您的不二之选。我们将深入剖析使用列表时出现“ RuntimeError:最大递归深度超出cmp”的各个方面,并为您解答最大递归深度超过比较的疑在这篇文章中,我们将为您介绍使用列表时出现“ RuntimeError:最大递归深度超出cmp”的相关知识,同时也会详细的解释最大递归深度超过比较的运用方法,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- 使用列表时出现“ RuntimeError:最大递归深度超出cmp”(最大递归深度超过比较)
- Django:python manage.py runserver提供了RuntimeError:在cmp中超过了最大递归深度
- javascript – 将Rails应用程序部署到Heroku时出现语法错误:ExecJS :: RuntimeError:SyntaxError:Unexpected character
- PHP报错:超出最大递归深度的解决方法!
- Python Tkinter:RecursionError:超过最大递归深度
使用列表时出现“ RuntimeError:最大递归深度超出cmp”(最大递归深度超过比较)
RuntimeError: maximum recursion depth exceeded in cmp
使用列表时遇到了错误。更确切地说,p0 inpoints
中,points.index(p0)
方法调用,以及在points.remove(p0)
上方法调用points
列表已经提出了具体的字典中的错误p0
在我的特定索引points
列表。points
发生错误时,该列表包含4700个字典,从12000个对象的列表中将一个字典减少一个,直到引发错误为止。该p0
词典包含在列表中,其中在返回包含对一个参考另一字典的参考p0
对象。在p0
还有字典它包含一个参考字典中出现两次points
是由上述三种方法调用引发错误之前列表。
此错误来自何处?
编辑 :这是引发错误的代码。
for roadType in roadTypes: points = roadPoints[roadType][:] while len(roadTails[roadType]) > 0: p0 = roadTails[roadType].pop() p1 = p0[''next''] points.remove(p0) # Where the error occurs points.remove(p1) while True: p2 = find(p1, points, 0.01) if p2: points.remove(p2) p3 = p2[''next''] points.remove(p3) if p3 in roadTails[roadType]: roadTails[roadType].remove(p3) break else: p0, p1 = p2, p3 continue else: break
这是的定义find
,其中dist
计算两点之间的距离。
def find(p1, points, tolerance = 0.01): for p2 in points: if dist(p2[''coords''], p1[''coords'']) <= tolerance: return p2 return False
这是错误的完整回溯:
Traceback (most recent call last): File "app.py", line 314, in <module> points.remove(p0) # Where the error occursRuntimeError: maximum recursion depth exceeded in cmp
答案1
小编典典可能您有一个循环结构,其中一个字典通过''next''
s链来引用自身,如下所示:
>>> a = {}>>> b = {}>>> a[''next''] = b>>> b[''next''] = a>>> a == bTraceback (most recent call last): File "<stdin>", line 1, in <module>RuntimeError: maximum recursion depth exceeded in cmp
如果打印出该字典,则循环引用将显示为...
:
>>> a{''next'': {''next'': {...}}}
也许这可以帮助找到该词典中有问题的部分。
Django:python manage.py runserver提供了RuntimeError:在cmp中超过了最大递归深度
我正在尝试从Django项目网站上的第1篇教程学习Django。我可能会缺少一些明显的东西,但是在遵循所有说明后,当我运行命令时
python manage.py runserver
我在请求的结尾处得到了错误消息,以寻求帮助(为简便起见,我仅将错误消息的重复行的前几行发布)。
这是我在网上找到的一些解决方案/建议,但对我没有帮助。
1)sys.setrecursionlimit(1500)。
这对我不起作用。
2)。DjangoRuntimeError:超过最大递归深度
这也不是一个选择,因为我没有使用PyDeV,我尝试使用pip卸载和安装Django,但它没有解决任何问题,并且我使用的是MountainLion的本机python,因为我们不建议将其卸载。
3)。我也尝试过:
python manage.py runserver --settings=mysite.settings
与没有选项设置的命令完全相同的错误
任何建议,建议将不胜感激。我正在使用…。Django正式版。我使用pip和Python 2.7.2安装的1.5.1
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10f7ee5d0>>Traceback (most recent call last): File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 92, in inner_run self.validate(display_num_errors=True) File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 280, in validate num_errors = get_validation_errors(s, app) File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors self._populate() File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 72, in _populate self.load_app(app_name, True) File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 96, in load_app models = import_module(''.models'', app_name) File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/Library/Python/2.7/site-packages/django/contrib/auth/models.py", line 370, in <module> class AbstractUser(AbstractBaseUser, PermissionsMixin): File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 213, in __new__ new_class.add_to_class(field.name, copy.deepcopy(field)) File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 265, in add_to_class value.contribute_to_class(cls, name) File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 257, in contribute_to_class cls._meta.add_field(self) File "/Library/Python/2.7/site-packages/django/db/models/options.py", line 179, in add_field self.local_fields.insert(bisect(self.local_fields, field), field) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> ''__lt__'': [(''__gt__'', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> ''__lt__'': [(''__gt__'', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> ''__lt__'': [(''__gt__'', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> ''__lt__'': [(''__gt__'', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> ''__lt__'': [(''__gt__'', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> ''__lt__'': [(''__gt__'', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> ''__lt__'': [(''__gt__'', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> ''__lt__'': [(''__gt__'', lambda self, other: other < self), RuntimeError: maximum recursion depth exceeded in cmp
更新:所以我最终要做的是对安装virtualbox,在其上安装免费的ubuntu,然后继续完成本教程进行大肆宣传…哦!
答案1
小编典典问题出在 functools.py 文件中。该文件来自Python。我刚刚安装了新版本的python 2.7.5,并且此文件是错误的(我还有另一个-
python 2.7.5的旧安装,并且那里的functools.py文件是正确的)
要解决此问题,请替换它(关于python \ Lib \ fuctools.py中的第56行):
convert = { ''__lt__'': [(''__gt__'', lambda self, other: other < self), (''__le__'', lambda self, other: not other < self), (''__ge__'', lambda self, other: not self < other)], ''__le__'': [(''__ge__'', lambda self, other: other <= self), (''__lt__'', lambda self, other: not other <= self), (''__gt__'', lambda self, other: not self <= other)], ''__gt__'': [(''__lt__'', lambda self, other: other > self), (''__ge__'', lambda self, other: not other > self), (''__le__'', lambda self, other: not self > other)], ''__ge__'': [(''__le__'', lambda self, other: other >= self), (''__gt__'', lambda self, other: not other >= self), (''__lt__'', lambda self, other: not self >= other)]}
对此:
convert = { ''__lt__'': [(''__gt__'', lambda self, other: not (self < other or self == other)), (''__le__'', lambda self, other: self < other or self == other), (''__ge__'', lambda self, other: not self < other)], ''__le__'': [(''__ge__'', lambda self, other: not self <= other or self == other), (''__lt__'', lambda self, other: self <= other and not self == other), (''__gt__'', lambda self, other: not self <= other)], ''__gt__'': [(''__lt__'', lambda self, other: not (self > other or self == other)), (''__ge__'', lambda self, other: self > other or self == other), (''__le__'', lambda self, other: not self > other)], ''__ge__'': [(''__le__'', lambda self, other: (not self >= other) or self == other), (''__gt__'', lambda self, other: self >= other and not self == other), (''__lt__'', lambda self, other: not self >= other)]}
另请阅读:http : //regebro.wordpress.com/2010/12/13/python-
implementing-rich-comparison-the-correct-
way/
javascript – 将Rails应用程序部署到Heroku时出现语法错误:ExecJS :: RuntimeError:SyntaxError:Unexpected character
“ExecJS::RuntimeError: SyntaxError: Unexpected character ‘`’ (line:
14577,col: 33,pos: 440811”
我认为coffeescript / javascript有问题.我删除了所有的coffeescript文件,我不知道我做错了什么.
正如Iceman所说,我试过运行命令
rake assets:precompile RAILS_ENV=development
它说
I,[2017-01-26T16:32:25.173928 #2674] INFO — : Writing >/Users/Gana/Documents/bombay/bombaydarbar/public/assets/circle->cb2239e32deac2eba5c693c3574b562595f1f933a8896866e47c170bf87c77e4.png
I,[2017-01-26T16:32:25.209986 #2674] INFO — : Writing >/Users/Gana/Documents/bombay/bombaydarbar/public/assets/fb->e361b3ecca9c24c6c05646b170fe25fcc185fa2eafb7aa46780253c8a9c79a04.png
I,[2017-01-26T16:32:25.225079 #2674] INFO — : Writing >/Users/Gana/Documents/bombay/bombaydarbar/public/assets/los->f083228761f6ede67e04a1a73906b4585bc5cfd3154ffec4861c4f04cf95aa32.jpg
I,[2017-01-26T16:32:25.253212 #2674] INFO — : Writing >/Users/Gana/Documents/bombay/bombaydarbar/public/assets/main->221235002689ad3847a67a05ce3608ebed4ee709be6fcf61bc0ccef2001b487f.jpg
I,[2017-01-26T16:32:25.272155 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/us-background-638489d758e08327ad62f883f11397bc870df84038b502ea17c3e2510cac6ef4.jpg
I,[2017-01-26T16:32:25.313969 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/zaisan-5f83c22eef3372c96199aad34ab9ad1744d6124e845a01267fcabcec39e2e948.jpg
I,[2017-01-26T16:32:25.426829 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/application-cadb51eb7487d2788eae31912fc18cc28ffaf8d48ea022d2a8a49c121415d7f8.js
I,[2017-01-26T16:32:25.427380 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/application-cadb51eb7487d2788eae31912fc18cc28ffaf8d48ea022d2a8a49c121415d7f8.js.gz
I,[2017-01-26T16:32:25.540537 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/application-8b6461ded0e51f6232fa5606fc47c47cd9b64684fbbeccd9fed16d7a0a66deee.css
I,[2017-01-26T16:32:25.540807 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/application-8b6461ded0e51f6232fa5606fc47c47cd9b64684fbbeccd9fed16d7a0a66deee.css.gz
I,[2017-01-26T16:32:25.543684 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/fontawesome-webfont-7bfcab6db99d5cfbf1705ca0536ddc78585432cc5fa41bbd7ad0f009033b2979.eot
I,[2017-01-26T16:32:25.597933 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/fontawesome-webfont-7bfcab6db99d5cfbf1705ca0536ddc78585432cc5fa41bbd7ad0f009033b2979.eot.gz
I,[2017-01-26T16:32:25.601098 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/fontawesome-webfont-2adefcbc041e7d18fcf2d417879dc5a09997aa64d675b7a3c4b6ce33da13f3fe.woff2
I,[2017-01-26T16:32:25.638449 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/fontawesome-webfont-ba0c59deb5450f5cb41b3f93609ee2d0d995415877ddfa223e8a8a7533474f07.woff
I,[2017-01-26T16:32:25.675384 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/fontawesome-webfont-aa58f33f239a0fb02f5c7a6c45c043d7a9ac9a093335806694ecd6d4edc0d6a8.ttf
I,[2017-01-26T16:32:25.716776 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/fontawesome-webfont-aa58f33f239a0fb02f5c7a6c45c043d7a9ac9a093335806694ecd6d4edc0d6a8.ttf.gz
I,[2017-01-26T16:32:25.721169 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/fontawesome-webfont-ad6157926c1622ba4e1d03d478f1541368524bfc46f51e42fe0d945f7ef323e4.svg
I,[2017-01-26T16:32:25.808396 #2674] INFO — : Writing /Users/Gana/Documents/bombay/bombaydarbar/public/assets/fontawesome-webfont-ad6157926c1622ba4e1d03d478f1541368524bfc46f51e42fe0d945f7ef323e4.svg.gz
我的图像文件有问题吗?
解决方法
Uglifier现在具有支持ES6 / ES2015语法的Harmony模式.
您可以通过传递来启用它:harmony => Uglifier的真正选项.
打开config / environments / production.rb
更换
config.assets.js_compressor = :uglifier
同
config.assets.js_compressor = Uglifier.new(harmony: true)
PHP报错:超出最大递归深度的解决方法!
PHP报错:超出最大递归深度的解决方法!
引言:
在使用PHP开发过程中,我们常常会遇到超出最大递归深度的问题。这个问题是由递归函数调用自身过多导致的,对于初学者来说可能会感到困惑。本文将介绍这个问题的原因,并提供几种解决方法,帮助大家更好地解决这一错误。
一、问题原因:
在PHP中,递归是一种非常重要的编程技术。通过递归函数,我们可以简化问题的复杂性,使代码更加简洁和可读。然而,当递归函数调用自身次数过多时,会导致超出PHP的最大递归深度限制,从而触发错误。
二、错误信息:
当代码超出最大递归深度时,PHP会抛出一个致命错误,错误信息类似于:
"Fatal error: Maximum function nesting level of ''xxx'' reached, aborting!"
立即学习“PHP免费学习笔记(深入)”;
其中,''xxx''代表PHP的最大递归深度限制,它可以通过更改php.ini配置文件的xdebug.max_nesting_level选项进行调整。
三、解决方法:
- 优化递归算法:
在遇到超出最大递归深度的问题时,可以尝试优化递归算法。优化的方式有很多种,例如,可以将递归函数拆分成多个函数,每个函数只负责一部分计算,然后通过函数间的参数传递结果。这样可以减少递归调用次数,降低递归深度。
以下是一个简单的示例代码:
function factorial($n){ // 递归出口 if($n == 0 || $n == 1){ return 1; } // 递归调用 return $n * factorial($n - 1); }
在这个示例中,我们可以通过尾递归优化来减少递归深度。将代码修改为以下形式:
function factorial($n, $result = 1){ // 递归出口 if($n == 0 || $n == 1){ return $result; } // 递归调用 return factorial($n - 1, $result * $n); }
这样一来,递归深度减少了,即使在较大的输入时也不容易触发最大递归深度限制。
- 增加递归深度限制:
如果优化递归算法不可行,我们可以尝试增加PHP的最大递归深度限制。在php.ini配置文件中,找到xdebug.max_nesting_level选项,并将其值调整为更大的数值。
例如,将其修改为:
xdebug.max_nesting_level = 1000
这样一来,递归深度限制将变为1000,就可以容纳更多的递归调用。
需要注意的是,调整递归深度限制可能存在一定的风险。如果递归调用过多,会导致内存消耗过大,甚至引起系统崩溃。因此,在增加递归深度限制之前,需谨慎评估代码的逻辑和运行环境。
结语:
超出最大递归深度是PHP开发中常见的问题,通过优化递归算法和适当调整递归深度限制,我们可以有效地解决这一问题。希望本文提供的解决方法能够帮助大家更好地处理这个报错,并使代码开发更加顺畅。
以上就是PHP报错:超出最大递归深度的解决方法!的详细内容,更多请关注php中文网其它相关文章!
Python Tkinter:RecursionError:超过最大递归深度
如果从SlideshowModel(tk.Tk,tk.Frame)类中删除“ tk.Tk”和“ tk.Frame”会发生什么?另外,您也应该将self.grid_height替换为self.grid_h(第22行)。
关于使用列表时出现“ RuntimeError:最大递归深度超出cmp”和最大递归深度超过比较的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Django:python manage.py runserver提供了RuntimeError:在cmp中超过了最大递归深度、javascript – 将Rails应用程序部署到Heroku时出现语法错误:ExecJS :: RuntimeError:SyntaxError:Unexpected character、PHP报错:超出最大递归深度的解决方法!、Python Tkinter:RecursionError:超过最大递归深度的相关信息,请在本站寻找。
本文标签: