Totally new to python, and i want to do the following:
I have this code:
def assem(myFile):
print "Hello ,World!"
import myParser
from myParser import Parser
import code
import symboleTable
from symboleTable import SymboleTable
newFile = "Prog.hack"
output = open(newFile, 'w')
input = open(myFile, '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()
checked the indentation, its ok,its a bit messy over here.
this program needs to run from console and receive a file named Add.asm
what is the console command to make it run?
tried :
python assembler.py Add.asm
did not work.
any idea?
optparse is indeed what you will need for more advanced cl options. However, you could
python assembler.py <filename>with a simpleif __name__ == "__main__"block. In lieu ofargparseoroptparse, you can usesys.argv[1]for a single simple argument to the script.You’ll also want to google
python string formattingand find links like http://docs.python.org/library/stdtypes.html#string-formatting