我在这里看一个非常有趣的网站 https://faust.readthedocs.io/en/latest/我对这段代码感到惊讶:
class Order(faust.Record):
account_id: str
product_id: str
price: float
quantity: float = 1.0
orders_topic = app.topic('orders', key_type=str, value_type=Order)
@app.agent(orders_topic)
async def process_order(orders):
async for order in orders:
# process each order using regular Python
total_price = order.price * order.quantity
await send_order_received_email(order.account_id, order)
我的问题是async for order in orders
是如何工作的?
什么版本的Python引入了这种语法?你知道吗
它是在Python 3.5中实现的:
https://www.python.org/dev/peps/pep-0492/#asynchronous-iterators-and-async-for
相关问题 更多 >
编程相关推荐