Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python RxPy中first()的用法_Python_Observable_Rx Py - Fatal编程技术网

Python RxPy中first()的用法

Python RxPy中first()的用法,python,observable,rx-py,Python,Observable,Rx Py,如何从RxPy中的可观察序列中恢复元素 obs = Observable.from_([1,2,3]) print obs.first() 应打印1,但它返回另一个匿名可观察,而不是元素 一般来说,从可观察序列中恢复元素的最佳操作符是什么?这对我很有用 obs = Observable.from_([1,2,3]) first = list(obs.first().to_blocking())[0] print(first) 调用to_blocking将序列转换为迭代器(类型为rx.core

如何从RxPy中的
可观察序列中恢复元素

obs = Observable.from_([1,2,3])
print obs.first()
应打印1,但它返回另一个
匿名可观察
,而不是元素

一般来说,从
可观察序列中恢复元素的最佳操作符是什么?

这对我很有用

obs = Observable.from_([1,2,3])
first = list(obs.first().to_blocking())[0]
print(first)
调用
to_blocking
将序列转换为迭代器(类型为rx.core.blockingobservable.blockingobservable),然后调用
list()

转换允许访问内部值。

欢迎回答,因此,概括说明您的解决方案有效而原始海报代码无效的原因可能会有所帮助,即您为什么要调用_blocking以及为什么要调用list()等。