Strange NameError: name 'math' is not defined, while "import math"
Strange NameError: name 'math' is not defined, while "import math"
我在执行这段代码时收到 NameError。这很奇怪,因为代码中有导入数学。 sigma 模块中有 import math ......也许这是一种冲突?
感谢您的宝贵时间!
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.
你可以从回溯中看出这一点;回溯是通过读取源文件并从字节码中获取嵌入的行号信息生成的 运行 显示源中的相应行。
但是你的回溯显示了 next 行的注释;字节码参考显然已过时,您更改了代码。
我也出现同样的错误,下面的操作对我有效:
改变
import math
至
from math import sqrt, ceil
所以我认为你可以单独从数学中导入你想使用的函数。
我在执行这段代码时收到 NameError。这很奇怪,因为代码中有导入数学。 sigma 模块中有 import math ......也许这是一种冲突? 感谢您的宝贵时间!
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.
你可以从回溯中看出这一点;回溯是通过读取源文件并从字节码中获取嵌入的行号信息生成的 运行 显示源中的相应行。
但是你的回溯显示了 next 行的注释;字节码参考显然已过时,您更改了代码。
我也出现同样的错误,下面的操作对我有效:
改变
import math
至
from math import sqrt, ceil
所以我认为你可以单独从数学中导入你想使用的函数。