Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a7b55a33
Commit
a7b55a33
authored
Feb 20, 2009
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revert r69777 since all the experts agree that extra import lines distract from the code
parent
5149742e
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
42 additions
and
96 deletions
+42
-96
Doc/howto/doanddont.rst
Doc/howto/doanddont.rst
+1
-2
Doc/howto/webservers.rst
Doc/howto/webservers.rst
+2
-5
Doc/includes/sqlite3/adapter_datetime.py
Doc/includes/sqlite3/adapter_datetime.py
+1
-2
Doc/library/asyncore.rst
Doc/library/asyncore.rst
+1
-2
Doc/library/cgi.rst
Doc/library/cgi.rst
+4
-8
Doc/library/configparser.rst
Doc/library/configparser.rst
+1
-2
Doc/library/cookielib.rst
Doc/library/cookielib.rst
+2
-5
Doc/library/crypt.rst
Doc/library/crypt.rst
+1
-3
Doc/library/csv.rst
Doc/library/csv.rst
+2
-5
Doc/library/difflib.rst
Doc/library/difflib.rst
+1
-5
Doc/library/doctest.rst
Doc/library/doctest.rst
+2
-4
Doc/library/fcntl.rst
Doc/library/fcntl.rst
+1
-3
Doc/library/getopt.rst
Doc/library/getopt.rst
+1
-2
Doc/library/gl.rst
Doc/library/gl.rst
+1
-3
Doc/library/imaplib.rst
Doc/library/imaplib.rst
+1
-2
Doc/library/imputil.rst
Doc/library/imputil.rst
+1
-3
Doc/library/logging.rst
Doc/library/logging.rst
+2
-5
Doc/library/modulefinder.rst
Doc/library/modulefinder.rst
+1
-2
Doc/library/pickle.rst
Doc/library/pickle.rst
+1
-2
Doc/library/poplib.rst
Doc/library/poplib.rst
+1
-2
Doc/library/signal.rst
Doc/library/signal.rst
+1
-2
Doc/library/sqlite3.rst
Doc/library/sqlite3.rst
+1
-2
Doc/library/ssl.rst
Doc/library/ssl.rst
+2
-5
Doc/library/stat.rst
Doc/library/stat.rst
+1
-2
Doc/library/sunaudio.rst
Doc/library/sunaudio.rst
+2
-4
Doc/library/termios.rst
Doc/library/termios.rst
+1
-2
Doc/library/traceback.rst
Doc/library/traceback.rst
+2
-4
Doc/library/xmlrpclib.rst
Doc/library/xmlrpclib.rst
+1
-2
Doc/tutorial/interactive.rst
Doc/tutorial/interactive.rst
+1
-2
Doc/tutorial/stdlib2.rst
Doc/tutorial/stdlib2.rst
+1
-2
Doc/whatsnew/2.6.rst
Doc/whatsnew/2.6.rst
+1
-2
No files found.
Doc/howto/doanddont.rst
View file @
a7b55a33
...
...
@@ -267,8 +267,7 @@ sequence with comparable semantics, for example, yet many people write their own
:func:`max`/:func:`min`. Another highly useful function is :func:`reduce`. A
classical use of :func:`reduce` is something like ::
import operator
import sys
import sys, operator
nums = map(float, sys.argv[1:])
print reduce(operator.add, nums)/len(nums)
...
...
Doc/howto/webservers.rst
View file @
a7b55a33
...
...
@@ -99,8 +99,7 @@ simple CGI program::
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
import cgitb; cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
...
...
@@ -280,9 +279,7 @@ following WSGI-application::
# -*- coding: UTF-8 -*-
from cgi import escape
import os
import sys
import sys, os
from flup.server.fcgi import WSGIServer
def app(environ, start_response):
...
...
Doc/includes/sqlite3/adapter_datetime.py
View file @
a7b55a33
import
datetime
import
sqlite3
import
time
import
datetime
,
time
def
adapt_datetime
(
ts
):
return
time
.
mktime
(
ts
.
timetuple
())
...
...
Doc/library/asyncore.rst
View file @
a7b55a33
...
...
@@ -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):
...
...
Doc/library/cgi.rst
View file @
a7b55a33
...
...
@@ -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
...
...
Doc/library/configparser.rst
View file @
a7b55a33
...
...
@@ -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'))
...
...
Doc/library/cookielib.rst
View file @
a7b55a33
...
...
@@ -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))
...
...
Doc/library/crypt.rst
View file @
a7b55a33
...
...
@@ -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:')
...
...
Doc/library/csv.rst
View file @
a7b55a33
...
...
@@ -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:
"""
...
...
Doc/library/difflib.rst
View file @
a7b55a33
...
...
@@ -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
...
...
Doc/library/doctest.rst
View file @
a7b55a33
...
...
@@ -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:
...
...
Doc/library/fcntl.rst
View file @
a7b55a33
...
...
@@ -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)
...
...
Doc/library/getopt.rst
View file @
a7b55a33
...
...
@@ -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:
...
...
Doc/library/gl.rst
View file @
a7b55a33
...
...
@@ -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()
...
...
Doc/library/imaplib.rst
View file @
a7b55a33
...
...
@@ -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())
...
...
Doc/library/imputil.rst
View file @
a7b55a33
...
...
@@ -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):
...
...
Doc/library/logging.rst
View file @
a7b55a33
...
...
@@ -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()
...
...
Doc/library/modulefinder.rst
View file @
a7b55a33
...
...
@@ -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
...
...
Doc/library/pickle.rst
View file @
a7b55a33
...
...
@@ -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')
...
...
Doc/library/poplib.rst
View file @
a7b55a33
...
...
@@ -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())
...
...
Doc/library/signal.rst
View file @
a7b55a33
...
...
@@ -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
...
...
Doc/library/sqlite3.rst
View file @
a7b55a33
...
...
@@ -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:
...
...
Doc/library/ssl.rst
View file @
a7b55a33
...
...
@@ -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))
...
...
Doc/library/stat.rst
View file @
a7b55a33
...
...
@@ -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):
...
...
Doc/library/sunaudio.rst
View file @
a7b55a33
...
...
@@ -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)
...
...
Doc/library/termios.rst
View file @
a7b55a33
...
...
@@ -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)
...
...
Doc/library/traceback.rst
View file @
a7b55a33
...
...
@@ -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()
...
...
Doc/library/xmlrpclib.rst
View file @
a7b55a33
...
...
@@ -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):
...
...
Doc/tutorial/interactive.rst
View file @
a7b55a33
...
...
@@ -99,8 +99,7 @@ Automatic completion of variable and module names is optionally available. To
enable it in the interpreter's interactive mode, add the following to your
startup file: [#]_ ::
import readline
import rlcompleter
import rlcompleter, readline
readline.parse_and_bind('tab: complete')
This binds the :kbd:`Tab` key to the completion function, so hitting the
...
...
Doc/tutorial/stdlib2.rst
View file @
a7b55a33
...
...
@@ -170,8 +170,7 @@ case is running I/O in parallel with computations in another thread.
The following code shows how the high level :mod:`threading` module can run
tasks in background while the main program continues to run::
import threading
import zipfile
import threading, zipfile
class AsyncZip(threading.Thread):
def __init__(self, infile, outfile):
...
...
Doc/whatsnew/2.6.rst
View file @
a7b55a33
...
...
@@ -473,8 +473,7 @@ statement both starts a database transaction and acquires a thread lock::
Finally
,
the
:
func
:`
closing
(
object
)`
function
returns
*
object
*
so
that
it
can
be
bound
to
a
variable
,
and
calls
``
object
.
close
``
at
the
end
of
the
block
.
::
import
sys
import
urllib
import
urllib
,
sys
from
contextlib
import
closing
with
closing
(
urllib
.
urlopen
(
'http://www.yahoo.com'
))
as
f
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment