为什么Python在我的模块中找不到第二个函数?

为什么Python在我的模块中找不到第二个函数?,python,module,python-import,Python,Module,Python Import,巨蟒新手。我正在尝试为Black-Scholes选项/LibreOffice Calc的希腊公式编写一些函数。我想制作一个包含各种函数的大模块,我需要在一些电子表格中使用这些函数。我把它们保存在一个名为tradingulities.py的文件中。前两个函数看起来像 def BSCall(S, K, r, sig, T): import scipy.stats as sp import numpy as np d1 = (np.log(S/K) - (r - 0.5 * s

巨蟒新手。我正在尝试为Black-Scholes选项/LibreOffice Calc的希腊公式编写一些函数。我想制作一个包含各种函数的大模块,我需要在一些电子表格中使用这些函数。我把它们保存在一个名为tradingulities.py的文件中。前两个函数看起来像

def BSCall(S, K, r, sig, T):
    import scipy.stats as sp
    import numpy as np
    d1 = (np.log(S/K) - (r - 0.5 * sig * sig) * T)/(sig*np.sqrt(T))
    d2 = d1 - sig*np.sqrt(T)
    P1 = sp.norm.cdf(d1)
    P2 = sp.norm.cdf(d2);
    call = S*P1 - K * np.exp(-r*T)*P2;
    return call
def BSPUt(S, K, r, sig, T):
    import scipy.stats as sp
    import numpy as np
    d1 = (np.log(S/K) - (r-0.5*sig*sig)*T)/(sig*np.sqrt(T))
    d2 = d1 - sig*np.sqrt(T)
    P1 = sp.norm.cdf(-d1)
    P2 = sp.norm.cdf(-d2)
    put = K*exp(-r*t)*P2 - S*P1
    return put
当我从命令行运行脚本时,第一个函数工作正常。但是当我试着运行第二个

>>> import TradingUtilities as tp
>>> tp.BSCall(238, 238.5, 0.05, 0.09, 0.09)
2.9860730330243541
>>> tp.BSPut(238, 238, 0.05, 0.09, 0.09)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'TradingUtilities' has no attribute 'BSPut'
我正试图找出问题所在,但到目前为止运气不好。如果有人能看到我做错了什么,或者给我指出了正确的方向,我将不胜感激


谢谢

您的代码中有输入错误

>>> tp.BSPut(238, 238, 0.05, 0.09, 0.09)
应该是

>>> tp.BSPUt(238, 238, 0.05, 0.09, 0.09)

或者您可以在主代码中将BSPUt更改为BSPUt。

与您在命令行中编写的相比,您的函数名中存在键入错误。Python区分大小写

应该是:
def BSPutS,K,r,sig,T:

如果需要,变量和函数中的“u”在定义中是大写的,而不是大写的,并带有下划线分隔符。只有类等类型的名称才应大写。这是目前的建议。请看:亲爱的上帝。我现在必须进行仪式性自杀来挽回我的名誉。谢谢,好先生。Python不仅仅是对功能误导的大小写敏感,人们可能只把它当作函数名,或者删除它,或者更清楚地知道什么是区分大小写。