使用这个脚本/模块,XRateDKKUSD_test.py,我可以成功获取 DKK pr USD 的汇率。
import pandas as pd
import pandas.io.data as web
import datetime
def xRate_pd(years,modus,start=datetime.datetime(2000,1,1),end=pd.Timestamp.utcnow()):
global xrate, xratedate, df_xrate
days = int(252 * years) # ant. arb. dage pr år = 252
if modus == 'sim':
start = datetime.datetime(2014,1,1) # indstil manuelt
end = datetime.datetime(2015,5,18) # indstil manuelt
if modus == 'trading':
end = pd.Timestamp.utcnow()
start = end - days * pd.tseries.offsets.BDay()
df_xrate = web.DataReader('DEXDNUS', 'fred',
start = start, end = end)
print('df_xrate \n',df_xrate)
# Selecting only last day from df, saving to xrate, xratedate
xrate = df_xrate.ix[-1, 'DEXDNUS']
xratedate = df_xrate.index[-1]
return xrate, xratedate, df_xrate
if __name__ == '__main__':
# xrate_lookup()
xRate_pd(modus='trading',years=0.25)
但是,当我尝试使用此功能从我的主程序运行此脚本时...
def xRate(start, end, years, modus):
global xrate, xratedate, df_xrate
xrate, xratedate, df_xrate = XRateDKKUSD_test.xRate_pd(start, end, modus)
return xrate, xratedate, df_xrate
使用此调用运行
import XRateDKKUSD_test
xRate_pd(start, end)
显然我已经在前面的函数中设置了“开始”和“结束”参数。
当脚本运行作为模块导入时,我突然遇到了这个脚本独立运行时没有得到的问题:
File "z:/python/crystallball/git - crystalball/_crystalball_main.py", line 277, in <module>
xRate_pd(start, end)
File "Z:/python/CrystallBall/Git - CrystalBall/XRateDKKUSD.py", line 55, in xRate_pd
days = int(252 * years)
TypeError: unsupported operand type(s) for *: 'int' and 'Timestamp'
任何人都知道为什么会存在这种差异,并且在我导入和运行脚本时会出错?