Python - IOError: [Errno 13] Permission denied:

It looks like you're trying to replace the extension with the following code:

if (myFile[-4:] == ".asm"):
    newFile = myFile[:4]+".hack"

However, you appear to have the array indexes mixed up. Try the following:

if (myFile[-4:] == ".asm"):
    newFile = myFile[:-4]+".hack"

Note the use of -4 instead of just 4 in the second line of code. This explains why your program is trying to create /Use.hack, which is the first four characters of your file name (/Use), with .hack appended to it.


You don't have sufficient permissions to write to the root directory. See the leading slash on the filename?


This happened to me when I was using 'shutil.copyfile' instead of 'shutil.copy'. The permissions were messed up.


Just Close the opened file where you are going to write.

Tags:

Python

Io

File