views:

557

answers:

4
+4  A: 

You can just call

python /path/to/filename.py
Peter
Erm...what exactly do you mean by call?
Sergio Tapia
Open a terminal, and type this in. This is for mac and linux, or for windows on cygwin. Perhaps others can answer for non-cygwin windows installations.
Peter
This will work on Windows also (except possibly for the forward slashes), but only if python is in the path. Getting it into the path takes more explanation than is available in this comment box.
Michael Myers
I think Papuccino1 problems lay a little bit earlier that that. I remember having that feel of not knowing where to go when you just have a new technology in your hands ( I still feel it from time to time with Java :P )
OscarRyz
by default on windows you could just do `filename.py`
SilentGhost
+3  A: 

Dive Into Python has a section on this that deals with how to launch it on different platforms. See Dive Into Python Chapter 2

Tim Hatch
The Windows section here seems very... *odd* and non-standard for how to launch it.
Gregg Lind
+5  A: 

In IDLE press F5

You can open your .py file with IDLE and press F5 to run it.

You can open that same file with other editor ( like Komodo as you said ) save it and press F5 again.

Here's a quick article about it: Getting Started with Python in IDLE

EDIT

F5 works with IDLE ( even when the editing is done with another tool )

If you want to run it directly from Komodo according to this article: Executing Python Code Within Komodo Edit you have to:

  1. go to Toolbox -> Add -> New Command...
  2. in the top field enter the name 'Run Python file'
  3. in the 'Command' field enter this text:

    %(python) %F 3.a optionall click on the 'Key Binding' tab and assign a key command to this command

  4. click Ok.
OscarRyz
In Komodo, I press F5 and nothing happens. :S Please check edited question for picture.
Sergio Tapia
You can open it with IDLE. Edit with Komodo and press F5 on IDLE every time you need to run it.
OscarRyz
+2  A: 

I'm very glad you asked! I was just working on explaining this very thing in our wikibook (which is obviously incomplete). We're working with Python novices, and had to help a few through exactly what you're asking!

Command-line Python in Windows:

  1. Save your python code file somewhere, using "Save" or "Save as" in your editor. Lets call it 'first.py' in some folder, like "pyscripts" that you make on your Desktop.

  2. Open a prompt (a Windows 'cmd' shell that is a text interface into the computer):

    start > run > "cmd" (in the little box). OK.

  3. Navigate to where your python file is, using the commands 'cd' (change directory) and 'dir' (to show files in the directory, to verify your head). For our example something like,

    > cd C:\Documents and Settings\Gregg\Desktop\pyscripts

  4. try:

    > python first.py

If you get this message:

'python' is not recognized as an internal or external command, operable program or batch file.

then python (the interpreter program that can translate Python into 'computer instructions') isn't on your path (see Putting Python in Your Path below). Then try calling it like this (assuming Python2.6, installed in the usual location):

> C:\Python26\python.exe first.py

(Advanced users: instead of first.py, you could write out first.py's full path of C:\Documents and Settings\Gregg\Desktop\pyscripts\first.py)

Putting Python In Your Path

Windows

In order to run programs, your operating system looks in various places, and tries to match the name of the program / command you typed with some programs along the way.

In windows:

control panel > system > advanced > |Environmental Variables| > system variables -> Path

this needs to include: C:\Python26; (or equivalent). If you put it at the front, it will be the first place looked. You can also add it at the end, which is possibly saner.

Then restart your prompt, and try typing 'python'. If it all worked, you should get a ">>>" prompt.

Gregg Lind