I'm trying to write a code that will read a file and make some manipulations on it.
the code:
def assem(file):
import myParser
from myParser import Parser
import code
import symboleTable
from symboleTable import SymboleTable
newFile = "Prog.hack"
output = open(newFile, 'w')
input = open(file, 'r')
prsr=Parser(input)
while prsr.hasMoreCommands():
str = "BLANK"
if(parser.commandType() == Parser.C_COMMAND):
str="111"+code.comp(prsr.comp())+code.dest(prsr.dest())+code.jump(prsr.jump())+"\n"
output.write(str)
prsr.advance()
the error i get:
Traceback (most recent call last):
File "assembler.py", line 11, in <module>
input = open(file, 'r')
TypeError: coercing to Unicode: need string or buffer, type found
how i run the program:
python assembler.py Add.asm
where Add.asm id the file i want to read, all modules are in the same library, including the .asm file.
fileis a built-in type in python, don't use this name for your variables. - georg