我正在Ocaml中编写一个编译器.当我make在终端中编译和测试它时,tracback运行良好,例如:
export OCAMLRUNPARAM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure("interp.ml", 45, 21)
Called from file "interp.ml", line 97, characters 72-86
Called from file "list.ml", line 74, characters 24-34
Called from file "interp.ml", line 108, characters 9-35
Called from file "main.ml", line 54, characters 4-17
make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)
但是当我在我的Emacs中编译并测试它Meta-x compile后make,它没有显示缓冲区中的回溯部分:
make
export OCAMLRUNPARAM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure("interp.ml", 45, 21)
make: *** [all] Error 2
Compilation exited abnormally with code 2 at Sat …Run Code Online (Sandbox Code Playgroud) 我已经设置了以下for循环来接受5个测试分数.我希望循环提示用户输入5个不同的分数.现在我可以通过输入"请输入你的下一个测试分数"输入来做到这一点,但我宁愿为每个输入的分数提示输入相关的数字.
因此,对于第一个输入,我希望它显示"请输入您的测试1的分数",然后在第二个分数中,显示"请输入您的测试2的分数".当我尝试运行此循环时,我收到以下错误:
Traceback(最近一次调用最后一次):
Traceback (most recent call last):
File "C:/Python32/Assignment 7.2", line 35, in <module>
main()
File "C:/Python32/Assignment 7.2", line 30, in main
scores = input_scores()
File "C:/Python32/Assignment 7.2", line 5, in input_scores
score = int(input('Please enter your score for test', y,' : '))
TypeError: input expected at most 1 arguments, got 3
Run Code Online (Sandbox Code Playgroud)
这是代码
def input_scores():
scores = []
y = 1
for num in range(5):
score = int(input('Please enter your score for test', y, ': '))
while score < …Run Code Online (Sandbox Code Playgroud) 构建一个简单的 Python 游戏“石头、剪刀、布”以供学习之用。
\n\n我在这里读过一些关于退出 Python 而不进行回溯的其他文章。我正在尝试实现它,但仍然得到回溯!一些 Python 专家可以指出这个 Python 假人出了什么问题吗?这个想法是,单击 RETURN(或输入“yes”或“y”将使程序再次运行 play(),但按 CTRL-C 将关闭它而不进行回溯。I\xc2\xb4m 使用 Python 2.7。
\n\n # modules\n import sys, traceback\n from random import choice\n\n #set up our lists\n ROCK, PAPER, SCISSORS = 1, 2, 3\n names = \'ROCK\', \'PAPER\', \'SCISSORS\'\n\n #Define a function for who beats who?\n def beats(a, b):\n return (a,b) in ((PAPER, ROCK), (SCISSORS, PAPER), (ROCK, SCISSORS))\n\n def play():\n print "Please select: "\n print "1 Rock"\n print "2 Paper"\n print "3 Scissors"\n # player …Run Code Online (Sandbox Code Playgroud) 尝试在 python 3 中使用 导入 glib 时from gi.repository import glib,我收到一条错误消息:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2135, in _find_spec
AttributeError: 'DynamicImporter' object has no attribute 'find_spec'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/gi/importer.py", line 53, in find_module
'introspection typelib not found' % namespace)
ImportError: cannot import name glib, introspection typelib not found
Run Code Online (Sandbox Code Playgroud)
我在 Ubuntu 14.04 上使用 apt-get 安装了所有 python glib/dev …
我试图读入包含产品数据的文档并打印出某些产品的数据。问题是,我似乎无法毫无错误地读取它。我只是想打印前 100 个字符来读取它,这样我就可以找出我需要打印的具体内容以及如何将其从文件中提取出来。但我一直在读它。文档是 UTF-8,或者应该是……我错过了什么?
这是我的代码:
products = open('products.csv')
productsread = products.read()
print(productsread[:100])
Run Code Online (Sandbox Code Playgroud)
这是我得到的回溯:
Traceback (most recent call last):
File "nilescratchpad.py", line 2, in <module>
productsread = products.read()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 7451: invalid continuation byte
Run Code Online (Sandbox Code Playgroud) 我有一个大的多边形数据集,并且通过循环,我尝试在某个时刻查找、计算和存储交点。在第 870 次迭代时,循环停止并出现错误:
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false, :
TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point 26.437120350000001 39.241770119999998 at 26.437120350000001 39.241770119999998
Run Code Online (Sandbox Code Playgroud)
我使用traceback()但我实际上无法理解它:
4: .Call("rgeos_intersection", .RGEOS_HANDLE, spgeom1, spgeom2,
byid, ids, PACKAGE = "rgeos")
3: RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false,
"rgeos_intersection")
2: gIntersection(combinations[[i]][[1, m]], combinations[[i]][[2,
m]]) at #17 . Can anyone explain what to look in ` traceback`?
Run Code Online (Sandbox Code Playgroud)
谁能解释一下该看什么traceback?
谢谢
我想查看代码直到特定点的完整跟踪
所以我这样做
...
import traceback
traceback.print_stack()
...
Run Code Online (Sandbox Code Playgroud)
然后就会显示
File ".venv/lib/python3.7/site-packages/django/db/models/query.py", line 144, in __iter__
return compiler.results_iter(tuple_expected=True, chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File ".venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1052, in results_iter
results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
File ".venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1100, in execute_sql
cursor.execute(sql, params)
File ".venv/lib/python3.7/site-packages/django/db/backends/utils.py", line 110, in execute
extra={'duration': duration, 'sql': sql, 'params': params}
File "/usr/lib64/python3.7/logging/__init__.py", line 1371, in debug
self._log(DEBUG, msg, args, **kwargs)
File "/usr/lib64/python3.7/logging/__init__.py", line 1519, in _log
self.handle(record)
File "/usr/lib64/python3.7/logging/__init__.py", line 1528, in handle
if (not self.disabled) and self.filter(record):
File "/usr/lib64/python3.7/logging/__init__.py", line …Run Code Online (Sandbox Code Playgroud) 我想知道是否有一种简单的方法可以防止Python回溯在出现错误时打印文件的完整路径。例如,下面的回溯打印生成异常的文件的绝对路径:
Traceback (most recent call last):
File "C:/Users/user/Documents/project/project_align/src/main.py", line 62, in <module>
raise Exception
Exception
Run Code Online (Sandbox Code Playgroud)
我希望它只打印相对路径:project_align/src/main.py
是否有某个配置参数可以强制执行此操作?
我有一个整数百分比列表,我需要使用以下模式打印:
Run Code Online (Sandbox Code Playgroud)The index of a value, a tab (8 spaces), a '*' printed for each percentage point
如果索引的值为0,则打印'小于1%'
我试过这段代码:
for b in new_tally:
if b > 0:
print new_tally[b], \t, '*' * b
else:
print 'Less than 1% of words had this length'
Run Code Online (Sandbox Code Playgroud)
但是我一直收到错误代码:列表索引超出范围.
我根本不明白这一点,有人能指出我做错了什么吗?
好吧基本上我写了一个不太漂亮的GUI,提供随机简单的数学问题.它就像我想要的那样工作.然而,每次我点击进入时,闲置的Shell会向我吐出红色.尽管如此,就像我说的那样,它继续按照我的意愿运作.所以我无法理解为什么我的代码的这个特定部分会导致问题.为长段代码道歉:
from tkinter import Label, Frame, Entry, Button, LEFT, RIGHT, END
from tkinter.messagebox import showinfo
import random
class Ed(Frame):
'Simple arithmetic education app'
def __init__(self,parent=None):
'constructor'
Frame.__init__(self, parent)
self.pack()
self.tries = 0
Ed.make_widgets(self)
Ed.new_problem(self)
def make_widgets(self):
'defines Ed widgets'
self.entry1 = Entry(self, width=20, bg="gray", fg ="black")
self.entry1.grid(row=0, column=0, columnspan=4)
self.entry1.pack(side = LEFT)
self.entry2 = Entry(self, width=20, bg="gray", fg ="black")
self.entry2.grid(row=2, column=2, columnspan=4)
self.entry2.pack(side = LEFT)
Button(self,text="ENTER", command=self.evaluate).pack(side = RIGHT)
def new_problem(self):
'creates new arithmetic problem'
opList = ["+", "-"]
a …Run Code Online (Sandbox Code Playgroud) traceback ×10
python ×7
arguments ×1
debugging ×1
decode ×1
emacs ×1
exception ×1
exit ×1
file ×1
function ×1
glib ×1
histogram ×1
importerror ×1
indexing ×1
list ×1
loops ×1
ocaml ×1
pretty-print ×1
python-2.7 ×1
python-3.8 ×1
python-3.x ×1
r ×1
tkinter ×1
unicode ×1