打开 GitHubCaps 打开了这个问题 2021 年 1 月 12 日 · 0 条评论 打开 CNC.py ZeroDivisionError in pathLength#1513 GitHubCaps 打开了这个问题 2021 年 1 月 12 日 · 0 条评论 评论 贡献者 GitHubCaps 评论了 2021 年 1 月 12 日 • 编辑 不确定这是何时实施的,但是,现在有一个问题。 elif self.gcode == 1 or self.gcode == 2 or self.gcode == 3 and self.feed > 0: block.time += length / self.feed # ZeroDivisionError: float division by zero self.totalTime += length / self.feed 编辑:我检查了 Python2.7 并且这有效,但在 Python3.8.2 中无效 NTS:Python3 的另一个复杂性更改(增强)使用。 强制使用正确的括号/圆括号! 这在两个方面都有效, elif (self.gcode == 1 or self.gcode == 2 or self.gcode == 3) and self.feed > 0: block.time += length / self.feed # ZeroDivisionError: float division by zero self.totalTime += length / self.feed 通过封装ors 但是,无论如何,我相信检查 仍然会更好ZeroDivisionError。 起初,我认为这是由于我正在测试的 Halftone 插件,但不是。 所以,我首先这样做,认为抛出一个 except 会解决它(确实如此,但仍然有问题)。 elif self.gcode == 1 or self.gcode == 2 or self.gcode == 3 and self.feed > 0: print("feed > 0:",self.feed) if self.feed > 0 else print("feed !> 0:",self.feed) try: block.time += length / self.feed # ZeroDivisionError: float division by zero self.totalTime += length / self.feed except ZeroDivisionError: print("gcode = %s %s\nfeed = %s %s\nlength = %s %s\n"%( self.gcode, type(self.gcode), self.feed, type(self.feed), length, type(length))) pass # Expect to have a ZeroDivisionError! except Exception as exc: # Always use another except during testing phases to catch other errors! print("Exception: %s\n in CNC::pathLength"%(exc)) 尽管如此 self.feed = 0,它还是过去了! 实际修复:首先检查 gcode,然后检查self.feed > 0. # # This as mentioned above # elif (self.gcode == 1 or self.gcode == 2 or self.gcode == 3) and self.feed > 0: # block.time += length / self.feed # ZeroDivisionError: float division by zero # self.totalTime += length / self.feed # or simply check gcode before feed elif self.gcode == 1 or self.gcode == 2 or self.gcode == 3: if self.feed > 0: block.time += length / self.feed self.totalTime += length / self.feed 编辑:已修复,我先检查提要,然后检查 gcode。 总之,这一行: elif self.gcode == 1 or self.gcode == 2 or self.gcode == 3 and self.feed > 0: 在 Python3 中不起作用(仅在 Python2 中) 出于测试目的:暂时尝试捕获所有内容。 elif self.gcode == 1 or self.gcode == 2 or self.gcode == 3: # XXX: Try to catch everything for now. if self.feed > 0: try: block.time += length / self.feed self.totalTime += length / self.feed except ZeroDivisionError: pass except Exception as exc: print("Exception: %s\n in CNC::pathLength"%(exc)) @Harvie希望在几天内,我会提交我发现/修复的大部分问题(有很多)。 如果你看一下Utils.py,出于某种奇怪的原因,import sys现在在那里两次! import sys import os import sys import glob import traceback import gettext 无论如何,我已经解决了很多其他编码/解码错误(这是我的首要任务) 免费注册 在 GitHub 上加入此对话。已有帐户? 登录评论 受让人 无人分配 标签 还没有 项目 还没有 里程碑 没有里程碑 发展 没有分支机构或拉取请求 1名参加者
不确定这是何时实施的,但是,现在有一个问题。
编辑:我检查了 Python2.7 并且这有效,但在 Python3.8.2 中无效
NTS:Python3 的另一个复杂性更改(增强)使用。
强制使用正确的括号/圆括号!
这在两个方面都有效,
通过封装
ors但是,无论如何,我相信检查 仍然会更好
ZeroDivisionError。起初,我认为这是由于我正在测试的 Halftone 插件,但不是。
所以,我首先这样做,认为抛出一个 except 会解决它(确实如此,但仍然有问题)。
尽管如此
self.feed = 0,它还是过去了!实际修复:首先检查 gcode,然后检查
self.feed > 0.编辑:已修复,我先检查提要,然后检查 gcode。
总之,这一行:
在 Python3 中不起作用(仅在 Python2 中)
出于测试目的:暂时尝试捕获所有内容。
@Harvie希望在几天内,我会提交我发现/修复的大部分问题(有很多)。
如果你看一下
Utils.py,出于某种奇怪的原因,import sys现在在那里两次!无论如何,我已经解决了很多其他编码/解码错误(这是我的首要任务)