Sir Fermion
Sir Fermion

Reputation: 1

How do I solve this CSV reader problem in python?

I'm trying to read a CSV file into python and I looked at different tutorials for it.

Input:

import csv

with open('test.csv', 'r') as csvdatei:
    csv_reader=csv.reader('test.csv')    
    for line in csv_reader:
        print(line)

Output:

['t']
['e']
['s']
['t']
['.']
['c']
['s']
['v']

Why does this not work? Why does it give me the split up file name as output?

I use python 3.7.3 on Spyder.

Upvotes: 0

Views: 43

Answers (1)

quamrana
quamrana

Reputation: 39354

I think you meant to give csv the contents of the file and not the filename:

import csv

with open('test.csv', 'r') as csvdatei:
    csv_reader = csv.reader(csvdatei)    
    for line in csv_reader:
        print(line)

Upvotes: 1

Related Questions