"Beginning Python" instead.">
  1. Computing

"Merry Christmas!": A Quick Tour of Python

From , former About.com Guide

2 of 7

Importing Modules and Assigning Values

First, let's import a module or two:

 import re, string, sys 

Then let's define the addressee, type of holiday, language and the punctuation for the output. These are taken from four command line arguments:

 addr = sys.argv[1] 
 hol = sys.argv[2] 
 lang = sys.argv[3] 
 punctuation = sys.argv[4] 

Here, we give addr the value of the first command-line argument of the program. The first word that comes after the program's name when the program is executed will be assigned using the sys module. The second word is sys.argv[2], etc. (the program's name itself is sys.argv[0]).

©2013 About.com. All rights reserved.