summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-02-20 03:31:23 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-02-20 03:31:23 (GMT)
commita7b55a33f877d1c210a5372a73ad85983ab8621c (patch)
treeccff5a2b2506f9b290e8c9f83be33bb3dfc16655 /Doc/library
parent5149742e8b3c8221d4cb53dcfc9a12ae3fec9238 (diff)
downloadcpython-a7b55a33f877d1c210a5372a73ad85983ab8621c.zip
cpython-a7b55a33f877d1c210a5372a73ad85983ab8621c.tar.gz
cpython-a7b55a33f877d1c210a5372a73ad85983ab8621c.tar.bz2
revert r69777 since all the experts agree that extra import lines distract from the code
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/asyncore.rst3
-rw-r--r--Doc/library/cgi.rst12
-rw-r--r--Doc/library/configparser.rst3
-rw-r--r--Doc/library/cookielib.rst7
-rw-r--r--Doc/library/crypt.rst4
-rw-r--r--Doc/library/csv.rst7
-rw-r--r--Doc/library/difflib.rst6
-rw-r--r--Doc/library/doctest.rst6
-rw-r--r--Doc/library/fcntl.rst4
-rw-r--r--Doc/library/getopt.rst3
-rw-r--r--Doc/library/gl.rst4
-rw-r--r--Doc/library/imaplib.rst3
-rw-r--r--Doc/library/imputil.rst4
-rw-r--r--Doc/library/logging.rst7
-rw-r--r--Doc/library/modulefinder.rst3
-rw-r--r--Doc/library/pickle.rst3
-rw-r--r--Doc/library/poplib.rst3
-rw-r--r--Doc/library/signal.rst3
-rw-r--r--Doc/library/sqlite3.rst3
-rw-r--r--Doc/library/ssl.rst7
-rw-r--r--Doc/library/stat.rst3
-rw-r--r--Doc/library/sunaudio.rst6
-rw-r--r--Doc/library/termios.rst3
-rw-r--r--Doc/library/traceback.rst6
-rw-r--r--Doc/library/xmlrpclib.rst3
25 files changed, 35 insertions, 81 deletions
diff --git a/Doc/library/asyncore.rst b/Doc/library/asyncore.rst
index e7ef925..4736a9c 100644
--- a/Doc/library/asyncore.rst
+++ b/Doc/library/asyncore.rst
@@ -246,8 +246,7 @@ asyncore Example basic HTTP client
Here is a very basic HTTP client that uses the :class:`dispatcher` class to
implement its socket handling::
- import asyncore
- import socket
+ import asyncore, socket
class http_client(asyncore.dispatcher):
diff --git a/Doc/library/cgi.rst b/Doc/library/cgi.rst
index 6ad061f..0248284 100644
--- a/Doc/library/cgi.rst
+++ b/Doc/library/cgi.rst
@@ -67,20 +67,16 @@ Begin by writing ``import cgi``. Do not use ``from cgi import *`` --- the
module defines all sorts of names for its own use or for backward compatibility
that you don't want in your namespace.
-When you write a new script, consider adding the following::
+When you write a new script, consider adding the line::
- import cgitb
-
- cgitb.enable()
+ import cgitb; cgitb.enable()
This activates a special exception handler that will display detailed reports in
the Web browser if any errors occur. If you'd rather not show the guts of your
program to users of your script, you can have the reports saved to files
-instead, with something like this::
-
- import cgitb
+instead, with a line like this::
- cgitb.enable(display=0, logdir="/tmp")
+ import cgitb; cgitb.enable(display=0, logdir="/tmp")
It's very helpful to use this feature during script development. The reports
produced by :mod:`cgitb` provide information that can save you a lot of time in
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index a04badb..1de11b9 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -231,8 +231,7 @@ RawConfigParser Objects
load the required file or files using :meth:`readfp` before calling :meth:`read`
for any optional files::
- import ConfigParser
- import os
+ import ConfigParser, os
config = ConfigParser.ConfigParser()
config.readfp(open('defaults.cfg'))
diff --git a/Doc/library/cookielib.rst b/Doc/library/cookielib.rst
index c52fca3..12a12a0 100644
--- a/Doc/library/cookielib.rst
+++ b/Doc/library/cookielib.rst
@@ -747,8 +747,7 @@ Examples
The first example shows the most common usage of :mod:`cookielib`::
- import cookielib
- import urllib2
+ import cookielib, urllib2
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
r = opener.open("http://example.com/")
@@ -756,9 +755,7 @@ The first example shows the most common usage of :mod:`cookielib`::
This example illustrates how to open a URL using your Netscape, Mozilla, or Lynx
cookies (assumes Unix/Netscape convention for location of the cookies file)::
- import cookielib
- import os
- import urllib2
+ import os, cookielib, urllib2
cj = cookielib.MozillaCookieJar()
cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt"))
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
diff --git a/Doc/library/crypt.rst b/Doc/library/crypt.rst
index f8d4f92..2f037c7 100644
--- a/Doc/library/crypt.rst
+++ b/Doc/library/crypt.rst
@@ -45,9 +45,7 @@ this module.
A simple example illustrating typical use::
- import crypt
- import getpass
- import pwd
+ import crypt, getpass, pwd
def login():
username = raw_input('Python login:')
diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
index 4b402b1..f19574b 100644
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -460,8 +460,7 @@ Registering a new dialect::
A slightly more advanced use of the reader --- catching and reporting errors::
- import csv
- import sys
+ import csv, sys
filename = "some.csv"
reader = csv.reader(open(filename, "rb"))
try:
@@ -507,9 +506,7 @@ For all other encodings the following :class:`UnicodeReader` and
parameter in their constructor and make sure that the data passes the real
reader or writer encoded as UTF-8::
- import codecs
- import cStringIO
- import csv
+ import csv, codecs, cStringIO
class UTF8Recoder:
"""
diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst
index 701c5d5..addd813 100644
--- a/Doc/library/difflib.rst
+++ b/Doc/library/difflib.rst
@@ -708,11 +708,7 @@ It is also contained in the Python source distribution, as
"""
- import difflib
- import os
- import optparse
- import sys
- import time
+ import sys, os, time, difflib, optparse
def main():
# Configure the option parser
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index 49db1c8..31e6d0f 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -951,11 +951,9 @@ Python 2.4, :mod:`doctest`'s :class:`Tester` class is deprecated, and
test suites from modules and text files containing doctests. These test suites
can then be run using :mod:`unittest` test runners::
- import doctest
import unittest
-
- import my_module_with_doctests
- import my_other_module_with_doctests
+ import doctest
+ import my_module_with_doctests, and_another
suite = unittest.TestSuite()
for mod in my_module_with_doctests, and_another:
diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst
index c9118f0..b3b977f 100644
--- a/Doc/library/fcntl.rst
+++ b/Doc/library/fcntl.rst
@@ -133,9 +133,7 @@ The module defines the following functions:
Examples (all on a SVR4 compliant system)::
- import fcntl
- import os
- import struct
+ import struct, fcntl, os
f = open(...)
rv = fcntl.fcntl(f, fcntl.F_SETFL, os.O_NDELAY)
diff --git a/Doc/library/getopt.rst b/Doc/library/getopt.rst
index 78958ee..2c0fad9 100644
--- a/Doc/library/getopt.rst
+++ b/Doc/library/getopt.rst
@@ -114,8 +114,7 @@ Using long option names is equally easy:
In a script, typical usage is something like this::
- import getopt
- import sys
+ import getopt, sys
def main():
try:
diff --git a/Doc/library/gl.rst b/Doc/library/gl.rst
index 6a0a92a..cbc175a 100644
--- a/Doc/library/gl.rst
+++ b/Doc/library/gl.rst
@@ -124,9 +124,7 @@ The following functions are non-standard or have special argument conventions:
Here is a tiny but complete example GL program in Python::
- import gl
- import GL
- import time
+ import gl, GL, time
def main():
gl.foreground()
diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst
index e0b824e..e18d7d5 100644
--- a/Doc/library/imaplib.rst
+++ b/Doc/library/imaplib.rst
@@ -521,8 +521,7 @@ IMAP4 Example
Here is a minimal example (without error checking) that opens a mailbox and
retrieves and prints all messages::
- import getpass
- import imaplib
+ import getpass, imaplib
M = imaplib.IMAP4()
M.login(getpass.getuser(), getpass.getpass())
diff --git a/Doc/library/imputil.rst b/Doc/library/imputil.rst
index d36d1a0..09a41f6 100644
--- a/Doc/library/imputil.rst
+++ b/Doc/library/imputil.rst
@@ -112,9 +112,7 @@ This code is intended to be read, not executed. However, it does work
::
- import __builtin__
- import imp
- import sys
+ import sys, imp, __builtin__
# Replacement for __import__()
def import_hook(name, globals=None, locals=None, fromlist=None):
diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst
index 554318a..8226661 100644
--- a/Doc/library/logging.rst
+++ b/Doc/library/logging.rst
@@ -1347,8 +1347,7 @@ Let's say you want to send logging events across a network, and handle them at
the receiving end. A simple way of doing this is attaching a
:class:`SocketHandler` instance to the root logger at the sending end::
- import logging
- import logging.handlers
+ import logging, logging.handlers
rootLogger = logging.getLogger('')
rootLogger.setLevel(logging.DEBUG)
@@ -2601,9 +2600,7 @@ properly preceded with the binary-encoded length, as the new logging
configuration::
#!/usr/bin/env python
- import socket
- import struct
- import sys
+ import socket, sys, struct
data_to_send = open(sys.argv[1], "r").read()
diff --git a/Doc/library/modulefinder.rst b/Doc/library/modulefinder.rst
index 9af5335..a086206 100644
--- a/Doc/library/modulefinder.rst
+++ b/Doc/library/modulefinder.rst
@@ -64,8 +64,7 @@ Example usage of :class:`ModuleFinder`
The script that is going to get analyzed later on (bacon.py)::
- import itertools
- import re
+ import re, itertools
try:
import baconhameggs
diff --git a/Doc/library/pickle.rst b/Doc/library/pickle.rst
index 8d153ec..a99dc86 100644
--- a/Doc/library/pickle.rst
+++ b/Doc/library/pickle.rst
@@ -708,8 +708,7 @@ The following example reads the resulting pickled data. When reading a
pickle-containing file, you should open the file in binary mode because you
can't be sure if the ASCII or binary format was used. ::
- import pickle
- import pprint
+ import pprint, pickle
pkl_file = open('data.pkl', 'rb')
diff --git a/Doc/library/poplib.rst b/Doc/library/poplib.rst
index 891e20e..e5f693d 100644
--- a/Doc/library/poplib.rst
+++ b/Doc/library/poplib.rst
@@ -182,8 +182,7 @@ POP3 Example
Here is a minimal example (without error checking) that opens a mailbox and
retrieves and prints all messages::
- import getpass
- import poplib
+ import getpass, poplib
M = poplib.POP3('localhost')
M.user(getpass.getuser())
diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst
index fbcee6b..3793a89 100644
--- a/Doc/library/signal.rst
+++ b/Doc/library/signal.rst
@@ -228,8 +228,7 @@ serial device that may not be turned on, which would normally cause the
before opening the file; if the operation takes too long, the alarm signal will
be sent, and the handler raises an exception. ::
- import os
- import signal
+ import signal, os
def handler(signum, frame):
print 'Signal handler called with signal', signum
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index 1a44284..d031c90 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -423,8 +423,7 @@ Connection Objects
Example::
# Convert file existing_db.db to SQL dump file dump.sql
- import os
- import sqlite3
+ import sqlite3, os
con = sqlite3.connect('existing_db.db')
with open('dump.sql', 'w') as f:
diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
index 572c566..30f1fea 100644
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -481,9 +481,7 @@ Client-side operation
This example connects to an SSL server, prints the server's address and certificate,
sends some bytes, and reads part of the response::
- import pprint
- import socket
- import ssl
+ import socket, ssl, pprint
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -537,8 +535,7 @@ For server operation, typically you'd need to have a server certificate, and pri
You'd open a socket, bind it to a port, call :meth:`listen` on it, then start waiting for clients
to connect::
- import socket
- import ssl
+ import socket, ssl
bindsocket = socket.socket()
bindsocket.bind(('myaddr.mydomain.com', 10023))
diff --git a/Doc/library/stat.rst b/Doc/library/stat.rst
index 835f448..430bb23 100644
--- a/Doc/library/stat.rst
+++ b/Doc/library/stat.rst
@@ -139,8 +139,7 @@ on the implementation of the underlying system call.
Example::
- import os
- import sys
+ import os, sys
from stat import *
def walktree(top, callback):
diff --git a/Doc/library/sunaudio.rst b/Doc/library/sunaudio.rst
index 4908cb4..4d67b21 100644
--- a/Doc/library/sunaudio.rst
+++ b/Doc/library/sunaudio.rst
@@ -135,13 +135,11 @@ methods (except ``control`` objects which only provide :meth:`getinfo`,
The audio device supports asynchronous notification of various events, through
the SIGPOLL signal. Here's an example of how you might enable this in Python::
- import fcntl
- import signal
- import STROPTS
-
def handle_sigpoll(signum, frame):
print 'I got a SIGPOLL update'
+ import fcntl, signal, STROPTS
+
signal.signal(signal.SIGPOLL, handle_sigpoll)
fcntl.ioctl(audio_obj.fileno(), STROPTS.I_SETSIG, STROPTS.S_MSG)
diff --git a/Doc/library/termios.rst b/Doc/library/termios.rst
index 38da7b4..4847949 100644
--- a/Doc/library/termios.rst
+++ b/Doc/library/termios.rst
@@ -91,8 +91,7 @@ technique using a separate :func:`tcgetattr` call and a :keyword:`try` ...
exactly no matter what happens::
def getpass(prompt = "Password: "):
- import sys
- import termios
+ import termios, sys
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst
index 29b09ae..1260037 100644
--- a/Doc/library/traceback.rst
+++ b/Doc/library/traceback.rst
@@ -145,8 +145,7 @@ less useful than) the standard Python interactive interpreter loop. For a more
complete implementation of the interpreter loop, refer to the :mod:`code`
module. ::
- import sys
- import traceback
+ import sys, traceback
def run_user_code(envdir):
source = raw_input(">>> ")
@@ -166,8 +165,7 @@ module. ::
The following example demonstrates the different ways to print and format the
exception and traceback::
- import sys
- import traceback
+ import sys, traceback
def lumberjack():
bright_side_of_death()
diff --git a/Doc/library/xmlrpclib.rst b/Doc/library/xmlrpclib.rst
index f5aa40e..4035f8e 100644
--- a/Doc/library/xmlrpclib.rst
+++ b/Doc/library/xmlrpclib.rst
@@ -551,8 +551,7 @@ transport. The following example shows how:
::
- import httplib
- import xmlrpclib
+ import xmlrpclib, httplib
class ProxiedTransport(xmlrpclib.Transport):
def set_proxy(self, proxy):