Python3中的异步for循环
我在这里看一个非常有趣的网站 我对这段代码感到惊讶:Python3中的异步for循环,python,python-3.x,Python,Python 3.x,我在这里看一个非常有趣的网站 我对这段代码感到惊讶: 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_o
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)
我的问题是orders中的async for order是如何工作的?
什么版本的Python引入了这种语法?它是在Python 3.5中实现的: Python版本:3.5 异步iterable可以在其iter实现中调用异步代码,异步迭代器可以在其下一个方法中调用异步代码
谢谢你Selcuk这真是太好了