Tinche / aiofiles

File support for asyncio
Apache License 2.0
2.67k stars 149 forks source link

How can i read a line and specific row #66

Closed britisharmy closed 4 years ago

britisharmy commented 4 years ago

I have this non async method

     def lastname():
        with open('surnames.csv') as csvfile:
             readCSV = csv.reader(csvfile, delimiter=',')
             for row in readCSV:
              print(row[0],row[1])

that reads a row

and i have this async

 async def firstname():
         async with aiofiles.open('firstnames.csv') as csvfile:
              readCSV  = await csvfile.read()
              return readCSV

How can i read a row in the async method?

zhangkaizhao commented 4 years ago

@britisharmy do you read the REAME:

Asynchronous iteration is also supported.

async with aiofiles.open('filename') as f:
    async for line in f:
        ...