【问题标题】:Python 2 error:"Internal Python error in the inspect modulePython 2 错误:“检查模块中的内部 Python 错误
【发布时间】:2016-05-20 20:10:43
【问题描述】:

我写了这段代码来计算二次公式:

from numpy.lib.scimath import sqrt as csqrt

a = raw_input("a?")

b = raw_input("b?")

c = raw_input("c?")

def numcheck(x):
    try:
       i = float(x)
       return True
    except (ValueError, TypeError):
       return False

if numcheck(a)==True:
    a=int(a)
else:
    print "a is not a number"

if numcheck(b)==True:
    b=int(b)
else:
    print "b is not a number"

if numcheck(c)==True:
    c=int(c)
else:
    print "b is not a number"


sqrt= ((b*b) - (4* (a*c)))

x_minus= (-b+(csqrt(sqrt)))/(2*a)
x_minus=str(x_minus)

x_plus= (-b-(csqrt(sqrt)))/(2*a)
x_plus=str(x_plus)

print "The solution is "+x_plus+" or "+x_minus

别在意那种相当蹩脚的风格,当输入不是数字时,我得到这个错误:

Traceback (most recent call last):
File "build\bdist.win32\egg\IPython\core\ultratb.py", line 776, in structured_traceback
File "build\bdist.win32\egg\IPython\core\ultratb.py", line 230, in wrapped
File "build\bdist.win32\egg\IPython\core\ultratb.py", line 267, in _fixed_getinnerframes
UnicodeDecodeError: 'ascii' codec can't decode byte 0xba in position 51: ordinal not in range(128)
ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.

Unfortunately, your original traceback can not be constructed.

谁能告诉我为什么会发生这种情况,如果可能的话,有办法解决它吗?谢谢。

【问题讨论】:

  • 看起来像一个 IPython 错误。
  • 有没有机会改用 Python 3?

标签: python python-2.x


【解决方案1】:

要做一个sqrt,你可以简单地这样做:

def sqrt(num):
    return num ** 0.5

我会尝试为您提供与您的问题相关的更多信息,但现在尝试将您的 sqrt 替换为那个。

【讨论】:

    猜你喜欢
    • 2020-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多