Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f43fbb

Browse files
Mariattavstinner
authored andcommitted
Use f-strings in asyncio-task code examples (GH-10035)
Replace str.format with f-strings in the code examples of asyncio-task documentation.
1 parent 057f407 commit 9f43fbb

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Doc/library/asyncio-task.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ To actually run a coroutine asyncio provides three main mechanisms:
5757
print(what)
5858

5959
async def main():
60-
print('started at', time.strftime('%X'))
60+
print(f"started at {time.strftime('%X')}")
6161

6262
await say_after(1, 'hello')
6363
await say_after(2, 'world')
6464

65-
print('finished at', time.strftime('%X'))
65+
print(f"finished at {time.strftime('%X')}")
6666

6767
asyncio.run(main())
6868

@@ -86,14 +86,14 @@ To actually run a coroutine asyncio provides three main mechanisms:
8686
task2 = asyncio.create_task(
8787
say_after(2, 'world'))
8888

89-
print('started at', time.strftime('%X'))
89+
print(f"started at {time.strftime('%X')}")
9090

9191
# Wait until both tasks are completed (should take
9292
# around 2 seconds.)
9393
await task1
9494
await task2
9595

96-
print('finished at', time.strftime('%X'))
96+
print(f"finished at {time.strftime('%X')}")
9797

9898
Note that expected output now shows that the snippet runs
9999
1 second faster than before::
@@ -603,9 +603,9 @@ Scheduling From Other Threads
603603
print('The coroutine took too long, cancelling the task...')
604604
future.cancel()
605605
except Exception as exc:
606-
print('The coroutine raised an exception: {!r}'.format(exc))
606+
print(f'The coroutine raised an exception: {exc!r}')
607607
else:
608-
print('The coroutine returned: {!r}'.format(result))
608+
print(f'The coroutine returned: {result!r}')
609609

610610
See the :ref:`concurrency and multithreading <asyncio-multithreading>`
611611
section of the documentation.

0 commit comments

Comments
 (0)