1. Home
  2. Computing & Technology
  3. Python

"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]).

Explore Python
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.