Jupyter Notebook,NameError:未定义,%% time阻止分配 [英] Jupyter Notebook, NameError: is not defined, %%time prevents assignment
问题描述
我在运行Jupyter Notebook(IPython:7.4.0)时遇到一个非常奇怪的错误,该错误未正常分配变量.我花了很多时间来找出原因,徒劳地寻找,变量范围,类型转换和TensorFlow的复杂性;(
I came across a very strange bug running a Jupyter Notebook (IPython: 7.4.0) where a variable was not assigned as normally. It took me quite bit of time to figure out the cause, searching in vain all over, variable scope, type conversion and TensorFlow intricacies ;(
事实上,使用%% time单元格魔术可以防止在单元格中分配变量.因此,在下面的单元格中未定义分配的变量,从而给出了典型的错误消息:未定义NameError:'xxx'."
In fact, using %%time cell magic was preventing assignment of the variable in the cell. Therefore the assigned variable was not defined in the cell below giving a characteristic error message: "NameError: 'xxx' is not defined."
这似乎是已知问题,希望可以对其他人有所帮助.
It seems to be a known issue, hoping that can help someone else.
推荐答案
解决方案很简单,只需从单元格中删除%% time.
The solution is simple, just remove %%time from the cell.
而是使用:
from timeit import default_timer as timer
from datetime import timedelta
start = timer()
# Process
# ...
end = timer()
print ("Execution time HH:MM:SS:",timedelta(seconds=end-start))
来源: Stackoverflow-测量Python中经过的时间?
这篇关于Jupyter Notebook,NameError:未定义,%% time阻止分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!