repl.it
@anonymous/

ThornyMobileCharacterencoding

Python

No description

fork
loading
Files
  • main.py
  • test.txt
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import asyncio
import contextlib
import aiofiles
import typing

@contextlib.asynccontextmanager
async def my_context_manager() -> typing.ContextManager[aiofiles.threadpool.AsyncFileIO]:
    # init
    filename = 'test.txt'

    async with aiofiles.open(filename, 'w+') as file:
        # you can still override or interact with `file` if needed
        yield file

async def main():
    # end user
    myfile: aiofiles.threadpool.AsyncFileIO
    async with my_context_manager() as myfile:
        print(await myfile.write("12\n"))
        await myfile.seek(0)
        print(await myfile.readline())

asyncio.run(main())
Fetching token
?