0

hi guys i am trying to build an automatic converter from xlsx to csv, here is my function that converts the file

def on_modified(self, event):
        print(f'event type: {event.event_type}  path : {event.src_path}')
        fileToConvert = pd.read_excel (event.src_path)
        fileToConvert.to_csv(pathOutput)

the event object is derived from a library and it returns the desired results, pd is how i imported pandas, but when i run the code i get this error

Traceback (most recent call last):
File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Python38\lib\site-packages\watchdog\observers\api.py", line 203, in run
self.dispatch_events(self.event_queue, self.timeout)
File "C:\Python38\lib\site-packages\watchdog\observers\api.py", line 376, in dispatch_events
handler.dispatch(event)
File "C:\Python38\lib\site-packages\watchdog\events.py", line 331, in dispatch
{
File "converter.py", line 12, in on_modified
fileToConvert.to_csv(pathOutput)
File "C:\Python38\lib\site-packages\pandas\core\generic.py", line 3170, in to_csv
formatter.save()
File "C:\Python38\lib\site-packages\pandas\io\formats\csvs.py", line 185, in save
f, handles = get_handle(
File "C:\Python38\lib\site-packages\pandas\io\common.py", line 493, in get_handle
f = open(path_or_buf, mode, encoding=encoding, errors=errors, newline="")
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\isaac\\Desktop\\converter_output' 

it basically gives me a permission error and i have tried running it as administrator but got the same error any help will be greatly appreciated thanks in advance

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

1 Answers1

0

Since you are on Window, the reason for permission error is you are writing to a folder that is write-protected and you need to show your code has permission to write into that folder. If you are running your code in the command prompt or Anaconda cmd, before running cmd, right-click on it and choose run as administrator. Then run your program and it will be fine. If you are running it in IDE (e.g. VS code) then close it and right-click on its icon and choose run as administrator.

Amin Gheibi
  • 639
  • 1
  • 8
  • 15