Posts

Showing posts from June, 2008

Run Python program in windows command prompt

To run Python program in windows, I have downloaded and installed python windows installer from http://www.python.org/download/ . IDLE is installed by default when I install the python windows installer. So python programs can be written and/or executed using IDLE. Or you can just double click a program to run it. Another way is to run from the windows command prompt. Right click on my computer. Then click Properties > Advanced > Environment Variables . Now edit the ' path ' variable. Add the location of python there (in my case it is F:\Python25). If there are more than one variables, each one should be separated by a semicolon (;). For example: Variable name: path Variable value: F:\TCWIN45\BIN;F:\Python25 Now you can run / execute a python program from windows command prompt using the following command: python abc.py You can also get the python interpreter if you just type python and press enter in the command prompt.

Function call in Python

Check the following code: def fibonacci(x): if x < 2: return 1 return (fibonacci(x-2) + fibonacci(x-1)) def factorial(x): if x < 2: return 1 return (x * factorial(x-1)) def main(): funcs = [fibonacci, factorial] n = 10 for i in range(len(funcs)): print funcs[i](n) main() Interesting part of the code is print funcs[i](n) . Sometimes it is useful to call the function in this way.