Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:28:53+00:00 2026-06-02T18:28:53+00:00

Totally new to python, and i want to do the following: I have this

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:28:56+00:00Added an answer on June 2, 2026 at 6:28 pm

    optparse is indeed what you will need for more advanced cl options. However, you could python assembler.py <filename> with a simple if __name__ == "__main__" block. In lieu of argparse or optparse, you can use sys.argv[1] for a single simple argument to the script.

    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()
    
    if __name__ == "__main__":
        import sys
        assem(sys.argv[1])
    

    You’ll also want to google python string formatting and find links like http://docs.python.org/library/stdtypes.html#string-formatting

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a totally new area for me so please be patient. I want
I'm totally new on this so I want to start with something simple. I
Totally new to Cake. I have this table named Content and another one named
I'm totally new to WPF. The following code snippet has the style/settings for a
I am totally new to SQL . I have a simple select query similar
Totally new to Drupal so be gentle please! Let's say I have a number
I just started to learn python, and i'm totally new and n00b. Normally i
I know PHP a little. But Python is totally new for me. I only
Totally new to Linux, have an Arch Linux machine up. What is the command
Good day, I am totally new to Python and I am trying to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.