| welcome to social.hackers | posts are made by Clocwork and Shadowdrifter | added some new hack diaries + podcasts |

Sunday, June 5, 2011

Python Programming Lesson Three.

     In programming lesson three we will be covering the os module of Python, which allows you to use command line functions inside a Python program. Now since most programs can be run from command line this has nearly unlimited possibilities. Unlike my other lesson this one requires some knowledge of command line depending on your operating system. Windows and Mac/Linux use somewhat different commands so this program will also be teaching you how to take a user’s input and use an IF command.

import os
opsys = raw_input("Are you using a Windows machine yes/no ")
if opsys =='yes':
                print 'This will use the windows echo and %random% function'
                os.system('echo %random%')
if opsys =='no':
                print 'This will use the linux echo command'
                os.system('echo hello')

      You may notice the indentions which is very important in Python.   We are using the IF command to determine which O.S the user is running so we can determine the appropriate commands to use.

No comments:

Post a Comment