How do I run a Python file from the Windows Command Line (cmd.exe) so that I won't have to re-enter the code each time?
-
3Do you really mean running it under a DOS operating system, or just in the Windows command line interpreter?Paggas– Paggas2009-10-23 17:37:47 +00:00Commented Oct 23, 2009 at 17:37
-
I was gonna say. I'd be very surprised if there's a version of Python that will run under MS-DOS.Robert Rossney– Robert Rossney2009-10-24 22:02:01 +00:00Commented Oct 24, 2009 at 22:02
-
@Robert Rossney: caddit.net/pythondLucas Jones– Lucas Jones2009-12-14 19:30:14 +00:00Commented Dec 14, 2009 at 19:30
7 Answers
If you don't want to install an IDE, you can also use IDLE which includes a Python editor and a console to test things out, this is part of the standard installation.
If you installed the python.org version, you will see an IDLE (Python GUI) in your start menu. I would recommend adding it to your Quick Launch or your desktop - whatever you are most familiar with. Then right-click on the shortcut you have created and change the "Start in" directory to your project directory or a place you can mess with, not the installation directory which is the default place and probably a bad idea.
When you double-click the shortcut it will launch IDLE, a console in which you can type in Python command and have history, completion, colours and so on. You can also start an editor to create a program file (like mentioned in the other posts). There is even a debugger.
If you saved your application in "test.py", you can start it from the editor itself. Or from the console with execfile("test.py"), import test (if that is a module), or finally from the debugger.
1 Comment
A good tool to have is the IPython shell. Not only can it run your program (%run command), but it offers also many tools for using Python interactively in an efficient manner (automatic completion, syntax coloring, quick access to the documentation, good interaction with Matplotlib,…). After you install it, you'll have access to its shell in the Start menu.
Comments
You need to create environment variables. Follow the instructions here: http://www.voidspace.org.uk/python/articles/command_line.shtml#environment-variables