Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

RichardGoodrich

  • one year ago

Anybody have python program that run's under IDLE but not directly from MacBook Pro terminal? I have been OK with MIT example programs either way. When I tried Peter Norvig's http://norvig.com/sudoku.html Sudoku Program it ran ONLY under IDLE. Anybody have an idea why?

  • This Question is Open
  1. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    That program won't run if invoked like: ./sudoku.py There's no sh-bang. An interpreted program, like Python, has to have: #!/usr/bin/python as the first line. The "#!" is referred to as a pound bang or sh-bang. That tells Unix that the following program (python) is to be started, and this file (sudoku.py) should be given to python for processing. The path to the interpreter has to be an absolute path. The line that I wrote will probably work fine for your Mac. The Python program has to have execute permissions. You should be able to run sudoku.py by invoking it like: python ./sudoku.py You don't need execute permissions on sudoku.py for this invocation.

  2. RichardGoodrich
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Well I tried that and no luck. I am attaching sudoku.py I go into terminal and type python to bring up the python shell. I am using MacVim as my editor but am new to it. I copy the file and paste it into the terminal window. When I invoke parse_grid(grid) I get the following error messages: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 8, in parse_grid File "<stdin>", line 5, in assign File "<stdin>", line 5, in <genexpr> NameError: global name 'eliminate' is not defined If I open IDLE and then File Open sudoku.py Run - Run Module then type parse_grid(grid) it works! I am trying to get to display(solve(grid)) which works under IDLE. grid_values(grid) works directly from the terminal, but very little else. I keep wondering if IDLE imports a module automatically that somehow I have missed when doing this directly from terminal. Appreciate the help! Shalom.

    1 Attachment
  3. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    TBH, I've never heard of MacVim. I use vi (vim VI iMproved) in Terminal/X11. Looking over your program, there's no __main__. No place for execution to start. If you want this to run as a program, append the following: if( __name__ == "__main__" ): grid_values(grid) If you want to test the individual functions, cd into the same directory as sudoku.py, In Terminal/X11 start Python: python Import sudoku.py: import sudoku Then you can run the individual functions: sudoku.grid_values(grid) with a value for grid.

  4. RichardGoodrich
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Ah thanks so much! I am definitely a noobie with Python and all things Apple!

  5. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    No problem. I've been programming in Python and a Systems/Network Admin since 1997, starting with IRIX and evolving into Macs.

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.