执行此代码时,我收到NameError。这很奇怪,因为代码中有导入数学。 sigma模块中有导入数学...也许有点冲突?
谢谢你的时间!

  File "C:\Users\Greenman\Documents\Python Scripts\sigma_crit.py", line 21, in sigma_crit
    # Simplified MC

NameError: name 'math' is not defined




import sigma as sgm # Module sigma has "import math" as well
import math
def sigma_crit(sigmaX, sigmaY, sigmaZ, Theta, Pw, Pres, nu, alpha, No):
    """
    Return value of critical stress calculated for one of three failure criterias.
    No: 1 - Simplified Mohr-Coulomb
        2 - Mohr-Coulomb
        3 - Drucker-Prager
        4 - list with 3 model's resutls
    sigmaX - stress at X wellbore axis
    sigmaY - stress at Y wellbore axis
    Theta - azimuth,anticlokwise from SH_max
    nu - Poisson's ratio
    alpha - Biot's  coefficient
    """
    sigma_theta = sgm.sigma_calc(sigmaX, sigmaY, sigmaZ, Theta, Pw, Pres, nu, alpha, 1)
    sigma_zi = sgm.sigma_calc(sigmaX, sigmaY, sigmaZ, Theta, Pw, Pres, nu, alpha, 2)
    sigma_thzi = sgm.sigma_calc(sigmaX, sigmaY, sigmaZ, Theta, Pw, Pres, nu, alpha,3)
    # Conerting degrees to radians for below equations...Caution above functions has built-in converter
    Theta = math.radians(Theta)
    # Simplified MC

最佳答案

您正在运行陈旧的字节码。您更改了源文件,但没有重新启动Python。

您可以从追溯中看到这一点;通过读取源文件并从正在运行的字节码中获取嵌入式行号信息以显示源中的相应行来生成回溯。

但是您的回溯将在下一行显示注释;字节码参考显然已过时,因此您更改了代码。

关于python - 奇怪的NameError:未定义名称“数学”,而“导入数学”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29078786/

10-15 02:00