So I'm starting like Python a bit, but I'm having trouble erm...running it. Lol
I'm using IDLE for now, but its no use whatsoever because you can only run a couple of lines at a time.
I'm also using Komodo Edit to create the actual .py files.
My question is, how can I run the .py files to test out the actual program?
I'm using Windows 7, and Komodo Edit 5 as my IDE. Pressing F5 in Komodo doesn't do anythin at all.
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; 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:
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
What I just did, to open a simple python script by double clicking. I just added a batch file to the directory containing the script:
@echo off
python exercise.py
pause>nul
(I have the python executable on my system path. If not one would need include its complete path of course.)
Then I just can double click on the batch file to run the script. The third line keeps the cmd window from being dismissed as soon as the script ends, so you can see the results. :) When you're done just close the command window.
If you want to run the #'.py' file just write in print() in your code to actually see it get printed. Unlike python IDLE, you need to specify what you want to print using print() command. For eg.
import os
os.getcwd()
a=[1,2,3,4,5]
name= 'Python'
# Use print() function
print(a)
print(name)
OUTPUT [1, 2, 3, 4, 5] Python
Navigate your file location just press Shift
button and click file name. Click tab Open command window here
and write in your command prompt python file_name.py
I have tried many of the commands listed above, however none worked, even after setting my path to include the directory where I installed Python.
The command py -3 file.py
always works for me, and if I want to run Python 2 code, as long as Python 2 is in my path, just changing the command to py -2 file.py
works perfectly.
I am using Windows, so I'm not too sure if this command will work on Linux, or Mac, but it's worth a try.
if you dont want call filename.py
you can add .PY
to the PATHEXT, that way you will just call filename
You can just call
python /path/to/filename.py
If this helps anyone, neither "python [filename].py" or "python.exe [filename.py]" worked for me, but "start python [filename].py" did. If anyone else is experiencing issues with the former two commands, try the latter one.
Python itself comes with an editor that you can access from the IDLE File > New File menu option.
Write the code in that file, save it as [filename].py and then (in that same file editor window) press F5 to execute the code you created in the IDLE Shell window.
Note: it's just been the easiest and most straightforward way for me so far.
Source: Stackoverflow.com