在IPython中将docstring计数为代码行

在IPython中将docstring计数为代码行,python,ipython,jupyter-notebook,Python,Ipython,Jupyter Notebook,我注意到,代码行从docstring结束的地方开始 但它给错误跟踪带来了问题,因为它指向的行与错误调用行实际存在的行不同 下面是一个简单的例子来说明: #comments #comments #comments #comments #comments #comments def divide(a,b): a = int(a) #convert a to an integer b = int(b) #convert b to an integer res = a/b #calculat

我注意到,代码行从docstring结束的地方开始

但它给错误跟踪带来了问题,因为它指向的行与错误调用行实际存在的行不同

下面是一个简单的例子来说明:

#comments
#comments
#comments
#comments
#comments
#comments
def divide(a,b):
  a = int(a)
#convert a to an integer
  b = int(b)
#convert b to an integer
  res = a/b
#calculate result  
  return res

divide(2,0)
错误

ZeroDivisionError回溯(最近一次调用)
在()
---->1除(2,0)
在(a,b)中
4b=int(b)
5#将b转换为整数
---->6 res=a/b
7#计算结果
8返回res
ZeroDivision错误:被零除
错误指向第6行,而实际位置为
12


有什么解决办法吗。

因为您没有全部运行,所以请尝试执行以下操作:

(哈哈,对不起我的字写得不好)

输出:


您正在使用哪个IDE?它给了我升华的第12行Text@AkshayNevrekar我说有什么问题?你不能找出回溯点是基于所示的信息吗?@奎师那,我认为你所做的是:所以每个单元格包含一个代码,而Juyter没有考虑每个单元格为一个。code@U9-转发3谢谢。抱歉打扰了。我这么做了。同样的结果。谷歌colab似乎有不同的规则。此外,这并不是针对Jupyter单元的,因为其他库中的模块在出现错误时指向的线太不同了。@krishna好的,那么我不知道,希望你们能解决它
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-56-030e2eec799d> in <module>()
----> 1 divide(2,0)

<ipython-input-55-9cd1ccec09c4> in divide(a, b)
      4   b = int(b)
      5 #convert b to an integer
----> 6   res = a/b
      7 #calculate result
      8   return res

ZeroDivisionError: division by zero