- publishing free software manuals
An Introduction to Python
by Guido van Rossum and Fred L. Drake, Jr.
Paperback (6"x9"), 124 pages
ISBN 0954161769
RRP £12.95 ($19.95)

Sales of this book support the Python Software Foundation! Get a printed copy>>>

10.7 Internet Access

There are a number of modules for accessing the internet and processing internet protocols. Two of the simplest are ‘urllib2’ for retrieving data from urls and ‘smtplib’ for sending mail:

    >>> import urllib2
    >>> url = 'http://tycho.usno.navy.mil/cgi-bin/timer.pl'
    >>> for line in urllib2.urlopen(url):
    ...     if 'EST' in line or 'EDT' in line:  
    ...         print line
    <BR>Nov. 25, 09:43:32 PM EST
    >>> import smtplib
    >>> server = smtplib.SMTP('localhost')
    >>> server.sendmail('soothsayer@example.org',
    """To: jcaesar@example.org
    From: soothsayer@example.org
    Beware the Ides of March.
    >>> server.quit()
ISBN 0954161769An Introduction to PythonSee the print edition