Wednesday, April 22, 2009

Running Python Scripts from a Command Prompt :

Actually, there are several ways to run your programs. First, let’s assume that you have a DOS 
window or a UNIX shell prompt before you, and that the directory containing the Python exe-
cutable (called python.exe in Windows, and python in UNIX) or the directory containing the 
executable (in Windows) has been put in your PATH environment variable.

Also, let’s assume that your script from the previous section (hello.py) is in the current directory. Then you can execute your script with the following command in

Windows: C:\>python hello.py

OR

UNIX: $ python hello.py

As you can see, the command is the same. Only the system prompt changes.

Note : If you don’t want to mess with environment variables, you can simply specify the full path of the Python interpreter.

In Windows, you might do something like this: C:\>C:\Python25\python hello.py

Saving and Executing Your Programs : 

First of all, you need a text editor, preferably one intended for programming. (If you use 
something like Microsoft Word, which I don’t really recommend, be sure to save your code as 
plain text.)

With IDLE, you can simply create a new editor window with File >> New Window.

Another window appears, without an interactive prompt.

Whew! Start by entering the following:

print "Hello, world!"

Now select File >> Save to save your program (which is, in fact, a plain text file).

Be sure to put it somewhere where you can find it later. You might want to create a directory where you put all your Python projects, such as C:\python in Windows.

In a UNIX environment, you might use a directory like ~/python. Give your file any reasonable name, such as hello.py. The .py ending is important.

Data Science - 103 (Kapil Sharma)

Cloud Computing Basic:-  In this the PC is on service provider data center and secuirty maintenance and upgrades are done by the service pro...