Simple Question regarding running .py program
d at davea.name
Tue Nov 13 03:24:38 CET 2012
On 11/12/2012 09:02 PM, Caroline Hou wrote:
> Hi all!
> I just started learning Python by myself and I have an extremely simple question now!
> I am in my Python interpreter now and I want to open/edit a program called nobel.py. But when I typed >>> python nobel.py, it gave me a "SyntaxError:invalid syntax”( I've changed to the correct directory)what should I do?
> I also want to run the program, but as I double-clicked the program, a command window pops up and closes immediately. How can I see the result of the program run?
> Could anyone help me please? I am pretty confused here...Thank you!
It'd be nice to specify that you're running Windows, and also what
version of the interpreter, although in this case the latter doesn't matter.
Go to a shell (cmd.exe), change to the directory containing that script,
and type the command as you did.
On linux: davea at think:~$ python nobel.py
On Windows: c:\mydir\myscript > python nobel.py
If you're already in the python interpreter, then running python is
useless -- it's already running. In that case, you might want to use
import. However, I recommend against it at first, as it opens up some
other problems you haven't experience with yet.
When you say you "double clicked the program', we have to guess you
might have meant in MS Explorer. If you do that, it launches a cmd, it
runs the python system, and it closes the cmd. Blame Windows for not
reading your mind. If you want the cmd window to stick around, you
COULD end your program with an raw_input function call, but frequently
that won't work. The right answer is the first one above... Open a
shell (perhaps with a menu like DOS BOX), change...
That way, when the program finishes, you can see what happened, or
didn't happen, and you can run it again using the uparrow key.
BTW, you don't need to send email to both the python-list and to the
newsgroup. The newsgroup is automatically fed from the list. But since
you're posting from google groups, that's just one of the bugs. Many
folks here simply filter out everything from google groups, so your post
is invisible to them.
More information about the Python-list