0

I am trying to reuse the code shown in the following SO post answer:

Especially the part that does:

async with sema, session.get(url) as response:
    response = await response.read()

But I don't understand it.. how can 2 "contexts" (sema and session.get(url)) be combined into 1 variable?

Can anyone give me a quick explanation of that syntax?

1 Answer 1

1

Value from sema's __aenter__ method is simply threw away and not assigned to any local variable.

Below is an equivalent for non-async code:

with ctx1, open(file) as fh:
    content = fh.read()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.