1

I am trying to understand how RxPy works, I am getting this error

type object 'ObservableBase' has no attribute 'create'

I am using python 3.6 and my code is

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))
scionoftech
  • 608
  • 2
  • 9
  • 24

2 Answers2

1

They have updated RxPy module. Install 1.6.1, it will solve the problem. Thanks

Indrajeet Singh
  • 470
  • 1
  • 6
  • 21
0

I have found the solution,

change the code from

from rx import Observable
source = Observable.create(buy_stock_events)

to

import rx
source = rx.Observable.create(buy_stock_events)

and it's working

scionoftech
  • 608
  • 2
  • 9
  • 24