我试图了解RxPy的工作原理,但出现此错误
类型对象“ ObservableBase”没有属性“创建”
我正在使用python 3.6,我的代码是
from rx import Observable
stocks = [
{'TCKR': 'APPL', 'PRICE': 200},
{'TCKR': 'GOOG', 'PRICE': 90},
{'TCKR': 'TSLA', 'PRICE': 120},
{'TCKR': 'MSFT', 'PRICE': 150},
{'TCKR': 'INTL', 'PRICE': 70},
{'TCKR': 'ELLT', 'PRICE': 0}
]
def buy_stock_events(observer):
for stock in stocks:
if (stock['PRICE'] > 100):
observer.on_next(stock['TCKR'])
elif (stock['PRICE'] <= 0):
observer.on_error(stock['TCKR'])
observer.on_completed()
source = Observable.create(buy_stock_events)
source.subscribe(on_next=lambda value: print("Received Instruction to buy {0}".format(value)),
on_completed=lambda: print("Completed trades"),
on_error=lambda e: print(e))
答案 0 :(得分:0)
我找到了解决方法,
更改
中的代码S (Add x' x)
到
from rx import Observable
source = Observable.create(buy_stock_events)
它正在工作
答案 1 :(得分:0)
他们已经更新了RxPy模块。安装1.6.1,即可解决问题。谢谢