0

I am trying to create a short program that reads lines in columns A, B, C and D in Excel, but keep receiving a file not found error and name error.

import csv
with open(London_Underground_data) as fp
    rows = list(csv.reader(fp))
for row in rows:
    for column in row[1:]:
        print(rows)
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • `London_Underground_data` is a variable name of a variable that doesn't exist. `open` expects a string as argument. You write a string by using quotes `''`. – mkrieger1 Nov 18 '20 at 15:40
  • Does this answer your question? [Python open() gives FileNotFoundError/IOError: Errno 2 No such file or directory](https://stackoverflow.com/questions/12201928/python-open-gives-filenotfounderror-ioerror-errno-2-no-such-file-or-directory) – mkrieger1 Nov 18 '20 at 15:42

1 Answers1

0

Assuming London_Underground_data is the name of your file in the directory:

import csv
with open("London_Underground_data") as fp
    rows = list(csv.reader(fp))
for row in rows:
    for column in row[1:]:
        print(rows)

Wrap your file name in quotes. open expects a string, and London_Underground_data is a variable name.

Alternate solution:

London_Underground_data = "/path/to/file"
import csv
with open(London_Underground_data) as fp
    rows = list(csv.reader(fp))
for row in rows:
    for column in row[1:]:
        print(rows)
blackbrandt
  • 2,010
  • 1
  • 15
  • 32