IOError: [Errno 13] Permission denied
#call to main function
if __name__ == '__main__':
from myParser import Parser
from symbolTable import SymbolTable
#max size of each word
WORD_SIZE = 16
#rom address to save to
rom_addrs = 0
#variable address to save to
var_addrs = 16
if (myFile[-4:] == ".asm"):
newFile = myFile[:4]+".hack"
output = open(newFile, 'w') <==== ERROR
IOError: [Errno 13] Permission denied: '/Use.hack'
python assembler.py Users/***/Desktop/University/Add.asm
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 (
.hack appended to it.