下面的代码工作在Python壳细,显示进料对象的内容:导入蟒模块在Django:__init__.py类未加载
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
strategy.BacktestingStrategy.__init__(self, feed)
self.__instrument = instrument
def onBars(self, bars):
bar = bars[self.__instrument]
self.info(bar.getClose())
feed = yahoofeed.Feed()
feed.addBarsFromCSV("orcl","data/bistampTicker.csv")
myStrategy = MyStrategy(feed, "orcl")
myStrategy.run()
然而,它在一个Django视图执行导致以下错误:
'function' object has no attribute 'BacktestingStrategy'
凡BacktestingStrategy是在Python模块的策略文件夹中的__ init__.py文件中定义的类,Python路径中。
我对这个问题的理解是,django没有读取__init__.py文件,因此没有正确导入模块(一个pyalgotrade模块)。
有没有办法让Django这么做?
在此先感谢您,并且对于无关紧要的问题感到抱歉。
干杯
我搜索了几个小时,在提交帖子后找到了解决方案的几分钟,修改了库,以便在strategy.py中定义策略类,而不是策略/__init__.py。不是非常优雅,但做的工作。 – Bertrand 2014-08-27 18:20:54