0

Hello I'm trying to access an excel file within python. I'm using this code we learned in class:

with open("file_name") as csv_file:
    csv_reader =csv.DictReader(csv_file)

and each time I run it I get the same error

PermissionError: [Errno 13] Permission denied: 'file_name' 

is there any code that I could run that would allow the command shell to read the file?

tsveti_iko
  • 6,834
  • 3
  • 47
  • 39
mgoal
  • 1
  • 1

1 Answers1

0

You need to change file_name with the correct path and file name, i.e.:

import csv
with open("/home/user/path/to/file.csv") as csv_file:
    csv_reader = csv.DictReader(csv_file)

For windows will look like:

import csv
with open("c:\\path\\to\\file.csv") as csv_file:
    csv_reader = csv.DictReader(csv_file)
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • So the new code is (with the file name): import os, csv os.mkdir('AI-Radar.csv') with open("c:\\path\\to\\AI-Radar.csv") as csv_file: csv_reader =csv.DictReader(csv_file but now it's saying that AI-Radar.csv is not in the directory and that's why I added the os.mkdir, but it still won't add it to the directory @Pedro Lobito – mgoal Nov 14 '19 at 12:56
  • I also have no clue how to edit my comments to make then look nice in the gray box so any tips for that would be amazing @pedro – mgoal Nov 14 '19 at 13:10
  • You cannot edit comments after 5 minutes. Make sure the path is correct and you should be good to go. – Pedro Lobito Nov 14 '19 at 13:26
  • I'm going to be honest I don't know what that means lol how do I change it to real path. is a path the AI-Radar.csv? – mgoal Nov 14 '19 at 14:31