Saturday, August 31, 2013

Execute Python Script in Windows


Simple Note

Simply type FILE_NAME.py then press Enter in cmd.

Code:

helloworld.py

h = "hello"
w = "world"
print(h + " " + w + "!")


Result:



Download:

https://github.com/benbai123/Python/blob/master/Practice/Basic/execute_script_file/helloworld.py

Reference:

http://docs.python.org/3.3/tutorial/interpreter.html

Execute System Command in Python


Simple Note

(Assume the command that can clear screen called cls and you want to clear screen in Python Interactive Mode)

import os lib then call os.system(COMMAND) as below:

Before:



After:


Python Getting Started


Simple Note

Steps

1. Go to download page (http://www.python.org/download/ for now) and download what you need (I choose Python 3.3.2 Windows x86 MSI Installer).

2. Execute downloaded file to install Python (Assume you installed it at C:\Python33).

3. Open command line and
    * Option A: go to the installed location (Assume C:\Python33)
    * Option B: type set path=%path%;C:\Python33 (for Windows) to make it accessible anywhere

4. Type "python", press Enter, type "help()", press Enter.



5. Go to tutorial page displayed in help message.

6. Go through tutorial to learn it.