Tinche / aiofiles

File support for asyncio
Apache License 2.0
2.76k stars 150 forks source link

Does aiofiles.write support to write a new line for each message? #150

Closed Jack012a closed 1 year ago

Jack012a commented 1 year ago
async with aiofiles.open('test.txt', mode='w') as f:
        await f.write(msg)

What is the best practice to write a new line for each written msg?

Thank you

Tinche commented 1 year ago

I'd say the same as for sync writes:

async with aiofiles.open('test.txt', mode='w') as f:
        await f.write(msg + '\n')
Jack012a commented 1 year ago

I see. Since the msg is very large. I will use the following instead.

async with aiofiles.open('test.txt', mode='w') as f:
        await f.write(msg)
        await f.write('\n')
Tinche commented 1 year ago

That works too, if you want to avoid a copy of the data.