Reputation: 42957
I am very very new in Python and I have a doubt.
If I write a program in a text editor (such as Nodepad++), then can I execute it from the Python shell (the one that begin with >>)? What command have I to launch to execute my Python program?
Tnx
Andrea
Upvotes: 0
Views: 430
Reputation: 1
In the view of mine: you wrote a program: test.py
print 'test file'
and you turn to the windows cmd: you excuted python,and you got this
>
then you can just simply:
os.system('python test.py')
Upvotes: 0
Reputation: 83245
From the Python console, you can run
execfile('program.py')
where program.py
is the path to your file.
EDIT:
In Python 3, you'd have to define execfile
yourself before you could use it. Copy and paste the following.
def execfile(path, globals=None, locals=None):
with open(path, "r") as file:
exec(file.read(), globals, locals)
You specifically asked for running it from the Python prompt, but if possible, consider running it from the normal command prompt (DOS, bash, etc.) It's a little easier, and more normal.
Upvotes: 5
Reputation: 353
from within the Python IDLE shell:
File -> Open... -> Select your Python program
When your program has openend select Run -> Run Module or press F5
Upvotes: 0
Reputation: 7257
you are done
Upvotes: 3