Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading line by line #26

Closed
britisharmy opened this issue Nov 25, 2019 · 1 comment
Closed

Reading line by line #26

britisharmy opened this issue Nov 25, 2019 · 1 comment

Comments

@britisharmy
Copy link

I have this csv file

"year","name","percent","sex"
1880,"John",0.081541,"boy"
1880,"William",0.080511,"boy"
1880,"James",0.050057,"boy"
1880,"Charles",0.045167,"boy"
1880,"George",0.043292,"boy"

and i want to read the second column.

I have this code

import asyncio
from aiofile import AIOFile, LineReader, Writer
async def main():

    async with AIOFile("file.csv", 'r') as afp:
        async for line in LineReader(afp):
            print(line[:10])


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

but this only reads the first 10 characters. How can i read the second column value of the simple csv attached here?.

@Natim
Copy link

Natim commented Nov 25, 2019

@britisharmy I guess your question is much more suited for StackOverflow than from the bug tracker of the lib.

However I believe you should read the CSV and then keep only the second column.

See https://docs.python.org/fr/3/library/csv.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants