How to read . csv file and use as a list in Python

Asked

Viewed 1,141 times

0

I need Python to read a CSV file and use the data in it as a list.

example of CSV data

francisco,
carlos,
melo,
luis,
claudia,

and I need that after reading Python use this data as this list below:

lista = (['francisco','carlos','melo','luis','claudia'])

I bumped into situations that he was sending line by line or had a line break \n disturbing or the comma ended up inside the simple quote: 'francisco,'. ........................................................................

Guys after hoooooras cracking their heads getting what they wanted. As I’m starting the details end up becoming big things.

I did it and it worked for me:

arq_listas = open('C:/...arq_listas.csv', 'r')
lista = arq_listas.read().split(',\n')
arq_listas.close()

the result I had was:

lista = (['francisco','carlos','melo','luis','claudia',''])

thanks for all your attention.

  • If you bumped into something, it means you tried, then add your code to the question and describe the result obtained. In fact, the format it presented is not exactly a CSV, but several lines that end with a comma. In CSV, this would represent multiple records of two columns, the second column always being null. It doesn’t seem that you want.

  • You’ve already solved the problem?

  • Anderson and Miguel, I managed to solve the problem. I edited my question including the solution that was viable for me. Thank you for your attention.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.