summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/_winreg.rst2
-rw-r--r--Doc/library/anydbm.rst2
-rw-r--r--Doc/library/asyncore.rst2
-rw-r--r--Doc/library/atexit.rst4
-rw-r--r--Doc/library/binascii.rst4
-rw-r--r--Doc/library/cgi.rst22
-rw-r--r--Doc/library/collections.rst10
-rw-r--r--Doc/library/contextlib.rst8
-rw-r--r--Doc/library/cookie.rst20
-rw-r--r--Doc/library/csv.rst8
-rw-r--r--Doc/library/ctypes.rst96
-rw-r--r--Doc/library/dbhash.rst4
-rw-r--r--Doc/library/decimal.rst22
-rw-r--r--Doc/library/difflib.rst16
-rw-r--r--Doc/library/doctest.rst44
-rw-r--r--Doc/library/email.generator.rst4
-rw-r--r--Doc/library/email.header.rst2
-rw-r--r--Doc/library/email.iterators.rst4
-rw-r--r--Doc/library/email.message.rst4
-rw-r--r--Doc/library/fnmatch.rst4
-rw-r--r--Doc/library/functions.rst4
-rw-r--r--Doc/library/functools.rst4
-rw-r--r--Doc/library/gdbm.rst2
-rw-r--r--Doc/library/getopt.rst2
-rw-r--r--Doc/library/gettext.rst12
-rw-r--r--Doc/library/heapq.rst4
-rw-r--r--Doc/library/htmlparser.rst4
-rw-r--r--Doc/library/httplib.rst6
-rw-r--r--Doc/library/imaplib.rst2
-rw-r--r--Doc/library/itertools.rst10
-rw-r--r--Doc/library/logging.rst2
-rw-r--r--Doc/library/macosa.rst2
-rw-r--r--Doc/library/mailbox.rst2
-rw-r--r--Doc/library/nntplib.rst4
-rw-r--r--Doc/library/optparse.rst4
-rw-r--r--Doc/library/os.rst6
-rw-r--r--Doc/library/pickle.rst6
-rw-r--r--Doc/library/poplib.rst2
-rw-r--r--Doc/library/pprint.rst7
-rw-r--r--Doc/library/profile.rst2
-rw-r--r--Doc/library/pyexpat.rst6
-rw-r--r--Doc/library/repr.rst2
-rw-r--r--Doc/library/rlcompleter.rst2
-rw-r--r--Doc/library/sched.rst6
-rw-r--r--Doc/library/signal.rst2
-rw-r--r--Doc/library/simplexmlrpcserver.rst8
-rw-r--r--Doc/library/smtplib.rst4
-rw-r--r--Doc/library/socket.rst12
-rw-r--r--Doc/library/sqlite3.rst2
-rw-r--r--Doc/library/ssl.rst4
-rw-r--r--Doc/library/stdtypes.rst21
-rw-r--r--Doc/library/sys.rst2
-rw-r--r--Doc/library/tabnanny.rst6
-rw-r--r--Doc/library/tokenize.rst4
54 files changed, 216 insertions, 234 deletions
diff --git a/Doc/library/_winreg.rst b/Doc/library/_winreg.rst
index fc185a2..033446f 100644
--- a/Doc/library/_winreg.rst
+++ b/Doc/library/_winreg.rst
@@ -383,7 +383,7 @@ an integer, however, use of the handle object is encouraged.
Handle objects provide semantics for :meth:`__bool__` - thus ::
if handle:
- print "Yes"
+ print("Yes")
will print ``Yes`` if the handle is currently valid (has not been closed or
detached).
diff --git a/Doc/library/anydbm.rst b/Doc/library/anydbm.rst
index 413b7de..f35a416 100644
--- a/Doc/library/anydbm.rst
+++ b/Doc/library/anydbm.rst
@@ -64,7 +64,7 @@ then prints out the contents of the database::
# Loop through contents. Other dictionary methods
# such as .keys(), .values() also work.
for k, v in db.iteritems():
- print k, '\t', v
+ print(k, '\t', v)
# Storing a non-string key or value will raise an exception (most
# likely a TypeError).
diff --git a/Doc/library/asyncore.rst b/Doc/library/asyncore.rst
index 7f80dd3..db98195 100644
--- a/Doc/library/asyncore.rst
+++ b/Doc/library/asyncore.rst
@@ -254,7 +254,7 @@ implement its socket handling::
self.close()
def handle_read(self):
- print self.recv(8192)
+ print(self.recv(8192))
def writable(self):
return (len(self.buffer) > 0)
diff --git a/Doc/library/atexit.rst b/Doc/library/atexit.rst
index cb2199a..f6c76de 100644
--- a/Doc/library/atexit.rst
+++ b/Doc/library/atexit.rst
@@ -80,7 +80,7 @@ Positional and keyword arguments may also be passed to :func:`register` to be
passed along to the registered function when it is called::
def goodbye(name, adjective):
- print 'Goodbye, %s, it was %s to meet you.' % (name, adjective)
+ print('Goodbye, %s, it was %s to meet you.' % (name, adjective))
import atexit
atexit.register(goodbye, 'Donny', 'nice')
@@ -94,7 +94,7 @@ Usage as a decorator::
@atexit.register
def goodbye():
- print "You are now leaving the Python sector."
+ print("You are now leaving the Python sector.")
This obviously only works with functions that don't take arguments.
diff --git a/Doc/library/binascii.rst b/Doc/library/binascii.rst
index ffea232..2ea0e50 100644
--- a/Doc/library/binascii.rst
+++ b/Doc/library/binascii.rst
@@ -110,11 +110,11 @@ The :mod:`binascii` module defines the following functions:
use as a checksum algorithm, it is not suitable for use as a general hash
algorithm. Use as follows::
- print binascii.crc32("hello world")
+ print(binascii.crc32("hello world"))
# Or, in two pieces:
crc = binascii.crc32("hello")
crc = binascii.crc32(" world", crc)
- print crc
+ print(crc)
.. function:: b2a_hex(data)
diff --git a/Doc/library/cgi.rst b/Doc/library/cgi.rst
index d2b88aa..84262f5 100644
--- a/Doc/library/cgi.rst
+++ b/Doc/library/cgi.rst
@@ -46,16 +46,16 @@ line. The first section contains a number of headers, telling the client what
kind of data is following. Python code to generate a minimal header section
looks like this::
- print "Content-Type: text/html" # HTML is following
- print # blank line, end of headers
+ print("Content-Type: text/html") # HTML is following
+ print() # blank line, end of headers
The second section is usually HTML, which allows the client software to display
nicely formatted text with header, in-line images, etc. Here's Python code that
prints a simple piece of HTML::
- print "<TITLE>CGI script output</TITLE>"
- print "<H1>This is my first CGI script</H1>"
- print "Hello, world!"
+ print("<TITLE>CGI script output</TITLE>")
+ print("<H1>This is my first CGI script</H1>")
+ print("Hello, world!")
.. _using-the-cgi-module:
@@ -104,11 +104,11 @@ string::
form = cgi.FieldStorage()
if not ("name" in form and "addr" in form):
- print "<H1>Error</H1>"
- print "Please fill in the name and addr fields."
+ print("<H1>Error</H1>")
+ print("Please fill in the name and addr fields.")
return
- print "<p>name:", form["name"].value
- print "<p>addr:", form["addr"].value
+ print("<p>name:", form["name"].value)
+ print("<p>addr:", form["addr"].value)
...further form processing here...
Here the fields, accessed through ``form[key]``, are themselves instances of
@@ -505,8 +505,8 @@ you can use an even more robust approach (which only uses built-in modules)::
import sys
sys.stderr = sys.stdout
- print "Content-Type: text/plain"
- print
+ print("Content-Type: text/plain")
+ print()
...your code here...
This relies on the Python interpreter to print the traceback. The content type
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 7a850b6..50ddc0f 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -105,7 +105,7 @@ Example::
>>> from collections import deque
>>> d = deque('ghi') # make a new deque with three items
>>> for elem in d: # iterate over the deque's elements
- ... print elem.upper()
+ ... print(elem.upper())
G
H
I
@@ -194,7 +194,7 @@ the tasklist if the input stream is not exhausted::
... pending.append(task)
...
>>> for value in roundrobin('abc', 'd', 'efgh'):
- ... print value
+ ... print(value)
a
d
@@ -221,7 +221,7 @@ two adjacent nodes into one by grouping them in a list::
... d.append(pair)
... return list(d)
...
- >>> print maketree('abcdefgh')
+ >>> print(maketree('abcdefgh'))
[[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]]
@@ -386,14 +386,14 @@ Setting the :attr:`default_factory` to :class:`set` makes the
import csv
EmployeeRecord = NamedTuple('EmployeeRecord', 'name age title department paygrade')
for record in starmap(EmployeeRecord, csv.reader(open("employees.csv", "rb"))):
- print record
+ print(record)
To cast an individual record stored as :class:`list`, :class:`tuple`, or some
other iterable type, use the star-operator [#]_ to unpack the values::
>>> Color = NamedTuple('Color', 'name code')
>>> m = dict(red=1, green=2, blue=3)
- >>> print Color(*m.popitem())
+ >>> print(Color(*m.popitem()))
Color(name='blue', code=3)
.. rubric:: Footnotes
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index 070dd88..decac44 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -26,12 +26,12 @@ Functions provided:
@contextmanager
def tag(name):
- print "<%s>" % name
+ print("<%s>" % name)
yield
- print "</%s>" % name
+ print("</%s>" % name)
>>> with tag("h1"):
- ... print "foo"
+ ... print("foo")
...
<h1>
foo
@@ -104,7 +104,7 @@ Functions provided:
with closing(urllib.urlopen('http://www.python.org')) as page:
for line in page:
- print line
+ print(line)
without needing to explicitly close ``page``. Even if an error occurs,
``page.close()`` will be called when the :keyword:`with` block is exited.
diff --git a/Doc/library/cookie.rst b/Doc/library/cookie.rst
index bd7cc1e..84ac72a 100644
--- a/Doc/library/cookie.rst
+++ b/Doc/library/cookie.rst
@@ -214,32 +214,32 @@ The following example demonstrates how to use the :mod:`Cookie` module. ::
>>> C = Cookie.SmartCookie()
>>> C["fig"] = "newton"
>>> C["sugar"] = "wafer"
- >>> print C # generate HTTP headers
+ >>> print(C) # generate HTTP headers
Set-Cookie: sugar=wafer
Set-Cookie: fig=newton
- >>> print C.output() # same thing
+ >>> print(C.output()) # same thing
Set-Cookie: sugar=wafer
Set-Cookie: fig=newton
>>> C = Cookie.SmartCookie()
>>> C["rocky"] = "road"
>>> C["rocky"]["path"] = "/cookie"
- >>> print C.output(header="Cookie:")
+ >>> print(C.output(header="Cookie:"))
Cookie: rocky=road; Path=/cookie
- >>> print C.output(attrs=[], header="Cookie:")
+ >>> print(C.output(attrs=[], header="Cookie:"))
Cookie: rocky=road
>>> C = Cookie.SmartCookie()
>>> C.load("chips=ahoy; vienna=finger") # load from a string (HTTP header)
- >>> print C
+ >>> print(C)
Set-Cookie: vienna=finger
Set-Cookie: chips=ahoy
>>> C = Cookie.SmartCookie()
>>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
- >>> print C
+ >>> print(C)
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"
>>> C = Cookie.SmartCookie()
>>> C["oreo"] = "doublestuff"
>>> C["oreo"]["path"] = "/"
- >>> print C
+ >>> print(C)
Set-Cookie: oreo=doublestuff; Path=/
>>> C = Cookie.SmartCookie()
>>> C["twix"] = "none for you"
@@ -252,7 +252,7 @@ The following example demonstrates how to use the :mod:`Cookie` module. ::
'7'
>>> C["string"].value
'seven'
- >>> print C
+ >>> print(C)
Set-Cookie: number=7
Set-Cookie: string=seven
>>> C = Cookie.SerialCookie()
@@ -262,7 +262,7 @@ The following example demonstrates how to use the :mod:`Cookie` module. ::
7
>>> C["string"].value
'seven'
- >>> print C
+ >>> print(C)
Set-Cookie: number="I7\012."
Set-Cookie: string="S'seven'\012p1\012."
>>> C = Cookie.SmartCookie()
@@ -272,7 +272,7 @@ The following example demonstrates how to use the :mod:`Cookie` module. ::
7
>>> C["string"].value
'seven'
- >>> print C
+ >>> print(C)
Set-Cookie: number="I7\012."
Set-Cookie: string=seven
diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
index 46302ef..11df7c2 100644
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -390,14 +390,14 @@ The simplest example of reading a CSV file::
import csv
reader = csv.reader(open("some.csv", "rb"))
for row in reader:
- print row
+ print(row)
Reading a file with an alternate format::
import csv
reader = csv.reader(open("passwd", "rb"), delimiter=':', quoting=csv.QUOTE_NONE)
for row in reader:
- print row
+ print(row)
The corresponding simplest possible writing example is::
@@ -420,7 +420,7 @@ A slightly more advanced use of the reader --- catching and reporting errors::
reader = csv.reader(open(filename, "rb"))
try:
for row in reader:
- print row
+ print(row)
except csv.Error as e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
@@ -429,7 +429,7 @@ done::
import csv
for row in csv.reader(['one,two,three']):
- print row
+ print(row)
The :mod:`csv` module doesn't directly support reading and writing Unicode, but
it is 8-bit-clean save for some problems with ASCII NUL characters. So you can
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst
index ac259e8..e9acedf 100644
--- a/Doc/library/ctypes.rst
+++ b/Doc/library/ctypes.rst
@@ -48,9 +48,9 @@ library containing most standard C functions, and uses the cdecl calling
convention::
>>> from ctypes import *
- >>> print windll.kernel32 # doctest: +WINDOWS
+ >>> print(windll.kernel32) # doctest: +WINDOWS
<WinDLL 'kernel32', handle ... at ...>
- >>> print cdll.msvcrt # doctest: +WINDOWS
+ >>> print(cdll.msvcrt) # doctest: +WINDOWS
<CDLL 'msvcrt', handle ... at ...>
>>> libc = cdll.msvcrt # doctest: +WINDOWS
>>>
@@ -82,9 +82,9 @@ Functions are accessed as attributes of dll objects::
>>> from ctypes import *
>>> libc.printf
<_FuncPtr object at 0x...>
- >>> print windll.kernel32.GetModuleHandleA # doctest: +WINDOWS
+ >>> print(windll.kernel32.GetModuleHandleA) # doctest: +WINDOWS
<_FuncPtr object at 0x...>
- >>> print windll.kernel32.MyOwnFunction # doctest: +WINDOWS
+ >>> print(windll.kernel32.MyOwnFunction) # doctest: +WINDOWS
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "ctypes.py", line 239, in __getattr__
@@ -145,9 +145,9 @@ handle.
This example calls both functions with a NULL pointer (``None`` should be used
as the NULL pointer)::
- >>> print libc.time(None) # doctest: +SKIP
+ >>> print(libc.time(None)) # doctest: +SKIP
1150640792
- >>> print hex(windll.kernel32.GetModuleHandleA(None)) # doctest: +WINDOWS
+ >>> print(hex(windll.kernel32.GetModuleHandleA(None))) # doctest: +WINDOWS
0x1d000000
>>>
@@ -269,12 +269,12 @@ the correct type and value::
Since these types are mutable, their value can also be changed afterwards::
>>> i = c_int(42)
- >>> print i
+ >>> print(i)
c_long(42)
- >>> print i.value
+ >>> print(i.value)
42
>>> i.value = -99
- >>> print i.value
+ >>> print(i.value)
-99
>>>
@@ -285,12 +285,12 @@ strings are immutable)::
>>> s = "Hello, World"
>>> c_s = c_char_p(s)
- >>> print c_s
+ >>> print(c_s)
c_char_p('Hello, World')
>>> c_s.value = "Hi, there"
- >>> print c_s
+ >>> print(c_s)
c_char_p('Hi, there')
- >>> print s # first string is unchanged
+ >>> print(s) # first string is unchanged
Hello, World
>>>
@@ -303,18 +303,18 @@ property::
>>> from ctypes import *
>>> p = create_string_buffer(3) # create a 3 byte buffer, initialized to NUL bytes
- >>> print sizeof(p), repr(p.raw)
+ >>> print(sizeof(p), repr(p.raw))
3 '\x00\x00\x00'
>>> p = create_string_buffer("Hello") # create a buffer containing a NUL terminated string
- >>> print sizeof(p), repr(p.raw)
+ >>> print(sizeof(p), repr(p.raw))
6 'Hello\x00'
- >>> print repr(p.value)
+ >>> print(repr(p.value))
'Hello'
>>> p = create_string_buffer("Hello", 10) # create a 10 byte buffer
- >>> print sizeof(p), repr(p.raw)
+ >>> print(sizeof(p), repr(p.raw))
10 'Hello\x00\x00\x00\x00\x00'
>>> p.value = "Hi"
- >>> print sizeof(p), repr(p.raw)
+ >>> print(sizeof(p), repr(p.raw))
10 'Hi\x00lo\x00\x00\x00\x00\x00'
>>>
@@ -444,7 +444,7 @@ a string pointer and a char, and returns a pointer to a string::
>>> strchr.restype = c_char_p # c_char_p is a pointer to a string
>>> strchr("abcdef", ord("d"))
'def'
- >>> print strchr("abcdef", ord("x"))
+ >>> print(strchr("abcdef", ord("x")))
None
>>>
@@ -460,7 +460,7 @@ single character Python string into a C char::
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ArgumentError: argument 2: exceptions.TypeError: one character string expected
- >>> print strchr("abcdef", "x")
+ >>> print(strchr("abcdef", "x"))
None
>>> strchr("abcdef", "d")
'def'
@@ -516,12 +516,12 @@ object in Python itself::
>>> i = c_int()
>>> f = c_float()
>>> s = create_string_buffer('\000' * 32)
- >>> print i.value, f.value, repr(s.value)
+ >>> print(i.value, f.value, repr(s.value))
0 0.0 ''
>>> libc.sscanf("1 3.14 Hello", "%d %f %s",
... byref(i), byref(f), s)
3
- >>> print i.value, f.value, repr(s.value)
+ >>> print(i.value, f.value, repr(s.value))
1 3.1400001049 'Hello'
>>>
@@ -549,10 +549,10 @@ constructor::
... ("y", c_int)]
...
>>> point = POINT(10, 20)
- >>> print point.x, point.y
+ >>> print(point.x, point.y)
10 20
>>> point = POINT(y=5)
- >>> print point.x, point.y
+ >>> print(point.x, point.y)
0 5
>>> POINT(1, 2, 3)
Traceback (most recent call last):
@@ -571,9 +571,9 @@ Here is a RECT structure which contains two POINTs named ``upperleft`` and
... ("lowerright", POINT)]
...
>>> rc = RECT(point)
- >>> print rc.upperleft.x, rc.upperleft.y
+ >>> print(rc.upperleft.x, rc.upperleft.y)
0 5
- >>> print rc.lowerright.x, rc.lowerright.y
+ >>> print(rc.lowerright.x, rc.lowerright.y)
0 0
>>>
@@ -585,9 +585,9 @@ Nested structures can also be initialized in the constructor in several ways::
Fields descriptors can be retrieved from the *class*, they are useful for
debugging because they can provide useful information::
- >>> print POINT.x
+ >>> print(POINT.x)
<Field type=c_long, ofs=0, size=4>
- >>> print POINT.y
+ >>> print(POINT.y)
<Field type=c_long, ofs=4, size=4>
>>>
@@ -622,9 +622,9 @@ item in the :attr:`_fields_` tuples::
... _fields_ = [("first_16", c_int, 16),
... ("second_16", c_int, 16)]
...
- >>> print Int.first_16
+ >>> print(Int.first_16)
<Field type=c_long, ofs=0:0, bits=16>
- >>> print Int.second_16
+ >>> print(Int.second_16)
<Field type=c_long, ofs=0:16, bits=16>
>>>
@@ -653,7 +653,7 @@ POINTs among other stuff::
... ("b", c_float),
... ("point_array", POINT * 4)]
>>>
- >>> print len(MyStruct().point_array)
+ >>> print(len(MyStruct().point_array))
4
>>>
@@ -661,7 +661,7 @@ Instances are created in the usual way, by calling the class::
arr = TenPointsArrayType()
for pt in arr:
- print pt.x, pt.y
+ print(pt.x, pt.y)
The above code print a series of ``0 0`` lines, because the array contents is
initialized to zeros.
@@ -671,9 +671,9 @@ Initializers of the correct type can also be specified::
>>> from ctypes import *
>>> TenIntegers = c_int * 10
>>> ii = TenIntegers(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
- >>> print ii
+ >>> print(ii)
<c_long_Array_10 object at 0x...>
- >>> for i in ii: print i,
+ >>> for i in ii: print(i, end=" ")
...
1 2 3 4 5 6 7 8 9 10
>>>
@@ -725,10 +725,10 @@ Pointer instances can also be indexed with integers::
Assigning to an integer index changes the pointed to value::
- >>> print i
+ >>> print(i)
c_long(99)
>>> pi[0] = 22
- >>> print i
+ >>> print(i)
c_long(22)
>>>
@@ -758,7 +758,7 @@ Calling the pointer type without an argument creates a ``NULL`` pointer.
``NULL`` pointers have a ``False`` boolean value::
>>> null_ptr = POINTER(c_int)()
- >>> print bool(null_ptr)
+ >>> print(bool(null_ptr))
False
>>>
@@ -797,7 +797,7 @@ pointer types. So, for ``POINTER(c_int)``, ctypes accepts an array of c_int::
>>> bar.values = (c_int * 3)(1, 2, 3)
>>> bar.count = 3
>>> for i in range(bar.count):
- ... print bar.values[i]
+ ... print(bar.values[i])
...
1
2
@@ -841,7 +841,7 @@ structure::
>>> bar = Bar()
>>> bar.values = cast((c_byte * 4)(), POINTER(c_int))
- >>> print bar.values[0]
+ >>> print(bar.values[0])
0
>>>
@@ -898,7 +898,7 @@ other, and finally follow the pointer chain a few times::
>>> c2.next = pointer(c1)
>>> p = c1
>>> for i in range(8):
- ... print p.name,
+ ... print(p.name, end=" ")
... p = p.next[0]
...
foo bar foo bar foo bar foo bar
@@ -952,7 +952,7 @@ For the first implementation of the callback function, we simply print the
arguments we get, and return 0 (incremental development ;-)::
>>> def py_cmp_func(a, b):
- ... print "py_cmp_func", a, b
+ ... print("py_cmp_func", a, b)
... return 0
...
>>>
@@ -980,7 +980,7 @@ And we're ready to go::
We know how to access the contents of a pointer, so lets redefine our callback::
>>> def py_cmp_func(a, b):
- ... print "py_cmp_func", a[0], b[0]
+ ... print("py_cmp_func", a[0], b[0])
... return 0
...
>>> cmp_func = CMPFUNC(py_cmp_func)
@@ -1016,7 +1016,7 @@ Ah, we're nearly done! The last step is to actually compare the two items and
return a useful result::
>>> def py_cmp_func(a, b):
- ... print "py_cmp_func", a[0], b[0]
+ ... print("py_cmp_func", a[0], b[0])
... return a[0] - b[0]
...
>>>
@@ -1051,7 +1051,7 @@ more comparisons than the linux version!
As we can easily check, our array is sorted now::
- >>> for i in ia: print i,
+ >>> for i in ia: print(i, end=" ")
...
1 5 7 33 99
>>>
@@ -1078,7 +1078,7 @@ the type. *pythonapi* is a predefined symbol giving access to the Python C
api::
>>> opt_flag = c_int.in_dll(pythonapi, "Py_OptimizeFlag")
- >>> print opt_flag
+ >>> print(opt_flag)
c_long(0)
>>>
@@ -1121,7 +1121,7 @@ access violation or whatever, so it's better to break out of the loop when we
hit the NULL entry::
>>> for item in table:
- ... print item.name, item.size
+ ... print(item.name, item.size)
... if item.name is None:
... break
...
@@ -1156,11 +1156,11 @@ Consider the following example::
>>> p1 = POINT(1, 2)
>>> p2 = POINT(3, 4)
>>> rc = RECT(p1, p2)
- >>> print rc.a.x, rc.a.y, rc.b.x, rc.b.y
+ >>> print(rc.a.x, rc.a.y, rc.b.x, rc.b.y)
1 2 3 4
>>> # now swap the two points
>>> rc.a, rc.b = rc.b, rc.a
- >>> print rc.a.x, rc.a.y, rc.b.x, rc.b.y
+ >>> print(rc.a.x, rc.a.y, rc.b.x, rc.b.y)
3 4 3 4
>>>
@@ -1214,7 +1214,7 @@ smaller than the natural memory block specified by the objects type, a
``ValueError`` is raised if this is tried::
>>> short_array = (c_short * 4)()
- >>> print sizeof(short_array)
+ >>> print(sizeof(short_array))
8
>>> resize(short_array, 4)
Traceback (most recent call last):
diff --git a/Doc/library/dbhash.rst b/Doc/library/dbhash.rst
index b5c9590..aadb14f 100644
--- a/Doc/library/dbhash.rst
+++ b/Doc/library/dbhash.rst
@@ -96,9 +96,9 @@ available in addition to the standard methods.
prints every key in the database ``db``, without having to create a list in
memory that contains them all::
- print db.first()
+ print(db.first())
for i in range(1, len(db)):
- print db.next()
+ print(db.next())
.. method:: dbhash.previous()
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst
index 498c2cc..444b20a 100644
--- a/Doc/library/decimal.rst
+++ b/Doc/library/decimal.rst
@@ -1052,7 +1052,7 @@ to work with the :class:`Decimal` class::
def pi():
"""Compute Pi to the current precision.
- >>> print pi()
+ >>> print(pi())
3.141592653589793238462643383
"""
@@ -1071,13 +1071,13 @@ to work with the :class:`Decimal` class::
def exp(x):
"""Return e raised to the power of x. Result type matches input type.
- >>> print exp(Decimal(1))
+ >>> print(exp(Decimal(1)))
2.718281828459045235360287471
- >>> print exp(Decimal(2))
+ >>> print(exp(Decimal(2)))
7.389056098930650227230427461
- >>> print exp(2.0)
+ >>> print(exp(2.0))
7.38905609893
- >>> print exp(2+0j)
+ >>> print(exp(2+0j))
(7.38905609893+0j)
"""
@@ -1095,11 +1095,11 @@ to work with the :class:`Decimal` class::
def cos(x):
"""Return the cosine of x as measured in radians.
- >>> print cos(Decimal('0.5'))
+ >>> print(cos(Decimal('0.5')))
0.8775825618903727161162815826
- >>> print cos(0.5)
+ >>> print(cos(0.5))
0.87758256189
- >>> print cos(0.5+0j)
+ >>> print(cos(0.5+0j))
(0.87758256189+0j)
"""
@@ -1118,11 +1118,11 @@ to work with the :class:`Decimal` class::
def sin(x):
"""Return the sine of x as measured in radians.
- >>> print sin(Decimal('0.5'))
+ >>> print(sin(Decimal('0.5')))
0.4794255386042030002732879352
- >>> print sin(0.5)
+ >>> print(sin(0.5))
0.479425538604
- >>> print sin(0.5+0j)
+ >>> print(sin(0.5+0j))
(0.479425538604+0j)
"""
diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst
index 8d130a1..ee973bc 100644
--- a/Doc/library/difflib.rst
+++ b/Doc/library/difflib.rst
@@ -194,7 +194,7 @@
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
... 'ore\ntree\nemu\n'.splitlines(1))
- >>> print ''.join(diff),
+ >>> print(''.join(diff), end="")
- one
? ^
+ ore
@@ -219,11 +219,11 @@
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
... 'ore\ntree\nemu\n'.splitlines(1))
>>> diff = list(diff) # materialize the generated delta into a list
- >>> print ''.join(restore(diff, 1)),
+ >>> print(''.join(restore(diff, 1)), end="")
one
two
three
- >>> print ''.join(restore(diff, 2)),
+ >>> print(''.join(restore(diff, 2)), end="")
ore
tree
emu
@@ -412,8 +412,8 @@ use :meth:`set_seq2` to set the commonly used sequence once and call
>>> b = "abycdf"
>>> s = SequenceMatcher(None, a, b)
>>> for tag, i1, i2, j1, j2 in s.get_opcodes():
- ... print ("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
- ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))
+ ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
+ ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
delete a[0:1] (q) b[0:0] ()
equal a[1:3] (ab) b[0:2] (ab)
replace a[3:4] (x) b[2:3] (y)
@@ -488,14 +488,14 @@ This example compares two strings, considering blanks to be "junk:" ::
sequences. As a rule of thumb, a :meth:`ratio` value over 0.6 means the
sequences are close matches::
- >>> print round(s.ratio(), 3)
+ >>> print(round(s.ratio(), 3))
0.866
If you're only interested in where the sequences match,
:meth:`get_matching_blocks` is handy::
>>> for block in s.get_matching_blocks():
- ... print "a[%d] and b[%d] match for %d elements" % block
+ ... print("a[%d] and b[%d] match for %d elements" % block)
a[0] and b[0] match for 8 elements
a[8] and b[17] match for 6 elements
a[14] and b[23] match for 15 elements
@@ -509,7 +509,7 @@ If you want to know how to change the first sequence into the second, use
:meth:`get_opcodes`::
>>> for opcode in s.get_opcodes():
- ... print "%6s a[%d:%d] b[%d:%d]" % opcode
+ ... print("%6s a[%d:%d] b[%d:%d]" % opcode)
equal a[0:8] b[0:8]
insert a[8:8] b[8:17]
equal a[8:14] b[17:23]
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index a448880..df1f6e3 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -309,11 +309,11 @@ your own :class:`DocTestParser` class.
>>> x
12
>>> if x == 13:
- ... print "yes"
+ ... print("yes")
... else:
- ... print "no"
- ... print "NO"
- ... print "NO!!!"
+ ... print("no")
+ ... print("NO")
+ ... print("NO!!!")
...
no
NO
@@ -340,7 +340,7 @@ The fine print:
>>> def f(x):
... r'''Backslashes in a raw docstring: m\n'''
- >>> print f.__doc__
+ >>> print(f.__doc__)
Backslashes in a raw docstring: m\n
Otherwise, the backslash will be interpreted as part of the string. For example,
@@ -349,7 +349,7 @@ The fine print:
>>> def f(x):
... '''Backslashes in a raw docstring: m\\n'''
- >>> print f.__doc__
+ >>> print(f.__doc__)
Backslashes in a raw docstring: m\n
* The starting column doesn't matter::
@@ -639,7 +639,7 @@ example. Use ``+`` to enable the named behavior, or ``-`` to disable it.
For example, this test passes::
- >>> print range(20) #doctest: +NORMALIZE_WHITESPACE
+ >>> print(range(20)) #doctest: +NORMALIZE_WHITESPACE
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
@@ -648,18 +648,18 @@ two blanks before the single-digit list elements, and because the actual output
is on a single line. This test also passes, and also requires a directive to do
so::
- >>> print range(20) # doctest: +ELLIPSIS
+ >>> print(range(20)) # doctest: +ELLIPSIS
[0, 1, ..., 18, 19]
Multiple directives can be used on a single physical line, separated by commas::
- >>> print range(20) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
+ >>> print(range(20)) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]
If multiple directive comments are used for a single example, then they are
combined::
- >>> print range(20) # doctest: +ELLIPSIS
+ >>> print(range(20)) # doctest: +ELLIPSIS
... # doctest: +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]
@@ -667,7 +667,7 @@ As the previous example shows, you can add ``...`` lines to your example
containing only directives. This can be useful when an example is too long for
a directive to comfortably fit on the same line::
- >>> print range(5) + range(10,20) + range(30,40) + range(50,60)
+ >>> print(range(5) + range(10,20) + range(30,40) + range(50,60))
... # doctest: +ELLIPSIS
[0, ..., 4, 10, ..., 19, 30, ..., 39, 50, ..., 59]
@@ -746,9 +746,9 @@ and C libraries vary widely in quality here. ::
>>> 1./7 # risky
0.14285714285714285
- >>> print 1./7 # safer
+ >>> print(1./7) # safer
0.142857142857
- >>> print round(1./7, 6) # much safer
+ >>> print(round(1./7, 6)) # much safer
0.142857
Numbers of the form ``I/2.**J`` are safe across all platforms, and I often
@@ -1518,7 +1518,7 @@ Doctest provides several mechanisms for debugging doctest examples:
>>> def f(x):
... g(x*2)
>>> def g(x):
- ... print x+3
+ ... print(x+3)
... import pdb; pdb.set_trace()
>>> f(3)
9
@@ -1533,10 +1533,10 @@ Doctest provides several mechanisms for debugging doctest examples:
-> import pdb; pdb.set_trace()
(Pdb) list
1 def g(x):
- 2 print x+3
+ 2 print(x+3)
3 -> import pdb; pdb.set_trace()
[EOF]
- (Pdb) print x
+ (Pdb) p x
6
(Pdb) step
--Return--
@@ -1546,7 +1546,7 @@ Doctest provides several mechanisms for debugging doctest examples:
1 def f(x):
2 -> g(x*2)
[EOF]
- (Pdb) print x
+ (Pdb) p x
3
(Pdb) step
--Return--
@@ -1571,14 +1571,14 @@ code under the debugger:
returned as a string. For example, ::
import doctest
- print doctest.script_from_examples(r"""
+ print(doctest.script_from_examples(r"""
Set x and y to 1 and 2.
>>> x, y = 1, 2
Print their sum:
- >>> print x+y
+ >>> print(x+y)
3
- """)
+ """))
displays::
@@ -1586,7 +1586,7 @@ code under the debugger:
x, y = 1, 2
#
# Print their sum:
- print x+y
+ print(x+y)
# Expected:
## 3
@@ -1607,7 +1607,7 @@ code under the debugger:
contains a top-level function :func:`f`, then ::
import a, doctest
- print doctest.testsource(a, "a.f")
+ print(doctest.testsource(a, "a.f"))
prints a script version of function :func:`f`'s docstring, with doctests
converted to code, and the rest placed in comments.
diff --git a/Doc/library/email.generator.rst b/Doc/library/email.generator.rst
index c12dc2f..6fc8ebe 100644
--- a/Doc/library/email.generator.rst
+++ b/Doc/library/email.generator.rst
@@ -27,7 +27,7 @@ Here are the public methods of the :class:`Generator` class, imported from the
The constructor for the :class:`Generator` class takes a file-like object called
*outfp* for an argument. *outfp* must support the :meth:`write` method and be
- usable as the output file in a Python extended print statement.
+ usable as the output file for the :func:`print` function.
Optional *mangle_from_* is a flag that, when ``True``, puts a ``>`` character in
front of any line in the body that starts exactly as ``From``, i.e. ``From``
@@ -72,7 +72,7 @@ The other public :class:`Generator` methods are:
Write the string *s* to the underlying file object, i.e. *outfp* passed to
:class:`Generator`'s constructor. This provides just enough file-like API for
- :class:`Generator` instances to be used in extended print statements.
+ :class:`Generator` instances to be used in the :func:`print` function.
As a convenience, see the methods :meth:`Message.as_string` and
``str(aMessage)``, a.k.a. :meth:`Message.__str__`, which simplify the generation
diff --git a/Doc/library/email.header.rst b/Doc/library/email.header.rst
index fb2496a..c426c95 100644
--- a/Doc/library/email.header.rst
+++ b/Doc/library/email.header.rst
@@ -31,7 +31,7 @@ example::
>>> msg = Message()
>>> h = Header('p\xf6stal', 'iso-8859-1')
>>> msg['Subject'] = h
- >>> print msg.as_string()
+ >>> print(msg.as_string())
Subject: =?iso-8859-1?q?p=F6stal?=
diff --git a/Doc/library/email.iterators.rst b/Doc/library/email.iterators.rst
index aa70141..f7ca9e4 100644
--- a/Doc/library/email.iterators.rst
+++ b/Doc/library/email.iterators.rst
@@ -60,6 +60,6 @@ The following function has been added as a useful debugging tool. It should
text/plain
text/plain
- Optional *fp* is a file-like object to print the output to. It must be suitable
- for Python's extended print statement. *level* is used internally.
+ Optional *fp* is a file-like object to print the output to. It must be
+ suitable for Python's :func:`print` function. *level* is used internally.
diff --git a/Doc/library/email.message.rst b/Doc/library/email.message.rst
index e494a71..7f3cf6f 100644
--- a/Doc/library/email.message.rst
+++ b/Doc/library/email.message.rst
@@ -167,7 +167,7 @@ included in the mapping interface.
the ``in`` operator, e.g.::
if 'message-id' in myMessage:
- print 'Message-ID:', myMessage['message-id']
+ print('Message-ID:', myMessage['message-id'])
.. method:: Message.__getitem__(name)
@@ -458,7 +458,7 @@ Here are some additional useful methods:
structure::
>>> for part in msg.walk():
- ... print part.get_content_type()
+ ... print(part.get_content_type())
multipart/report
text/plain
message/delivery-status
diff --git a/Doc/library/fnmatch.rst b/Doc/library/fnmatch.rst
index 6ce5a1c..a75ca7c 100644
--- a/Doc/library/fnmatch.rst
+++ b/Doc/library/fnmatch.rst
@@ -51,7 +51,7 @@ patterns.
for file in os.listdir('.'):
if fnmatch.fnmatch(file, '*.txt'):
- print file
+ print(file)
.. function:: fnmatchcase(filename, pattern)
@@ -78,7 +78,7 @@ patterns.
>>> regex
'.*\\.txt$'
>>> reobj = re.compile(regex)
- >>> print reobj.match('foobar.txt')
+ >>> print(reobj.match('foobar.txt'))
<_sre.SRE_Match object at 0x...>
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index ff16536..056e2d5 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -325,7 +325,7 @@ available. They are listed here in alphabetical order.
``(1, seq[1])``, ``(2, seq[2])``, .... For example::
>>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter')]:
- >>> print i, season
+ >>> print(i, season)
0 Spring
1 Summer
2 Fall
@@ -350,7 +350,7 @@ available. They are listed here in alphabetical order.
the evaluated expression. Syntax errors are reported as exceptions. Example::
>>> x = 1
- >>> print eval('x+1')
+ >>> eval('x+1')
2
This function can also be used to execute arbitrary code objects (such as those
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst
index a25fde9..a3d3729 100644
--- a/Doc/library/functools.rst
+++ b/Doc/library/functools.rst
@@ -92,14 +92,14 @@ The :mod:`functools` module defines the following functions:
>>> def my_decorator(f):
... @wraps(f)
... def wrapper(*args, **kwds):
- ... print 'Calling decorated function'
+ ... print('Calling decorated function')
... return f(*args, **kwds)
... return wrapper
...
>>> @my_decorator
... def example():
... """Docstring"""
- ... print 'Called example function'
+ ... print('Called example function')
...
>>> example()
Calling decorated function
diff --git a/Doc/library/gdbm.rst b/Doc/library/gdbm.rst
index ce27f6c..f69e667 100644
--- a/Doc/library/gdbm.rst
+++ b/Doc/library/gdbm.rst
@@ -93,7 +93,7 @@ methods:
k = db.firstkey()
while k != None:
- print k
+ print(k)
k = db.nextkey(k)
diff --git a/Doc/library/getopt.rst b/Doc/library/getopt.rst
index 7ead8ea..b7220a5 100644
--- a/Doc/library/getopt.rst
+++ b/Doc/library/getopt.rst
@@ -112,7 +112,7 @@ In a script, typical usage is something like this::
opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
except getopt.GetoptError as err:
# print help information and exit:
- print str(err) # will print something like "option -a not recognized"
+ print(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
output = None
diff --git a/Doc/library/gettext.rst b/Doc/library/gettext.rst
index af82f96..1940ec9 100644
--- a/Doc/library/gettext.rst
+++ b/Doc/library/gettext.rst
@@ -126,7 +126,7 @@ Here's an example of typical usage for this API::
gettext.textdomain('myapplication')
_ = gettext.gettext
# ...
- print _('This is a translatable string.')
+ print(_('This is a translatable string.'))
Class-based API
@@ -201,7 +201,7 @@ the built-in namespace as the function :func:`_`.
candidates for translation, by wrapping them in a call to the :func:`_`
function, like this::
- print _('This string will be translated.')
+ print(_('This string will be translated.'))
For convenience, you want the :func:`_` function to be installed in Python's
builtin namespace, so it is easily accessible in all modules of your
@@ -446,7 +446,7 @@ version has a slightly different API. Its documented usage was::
import gettext
cat = gettext.Catalog(domain, localedir)
_ = cat.gettext
- print _('hello world')
+ print(_('hello world'))
For compatibility with this older module, the function :func:`Catalog` is an
alias for the :func:`translation` function described above.
@@ -604,7 +604,7 @@ translation until later. A classic example is::
]
# ...
for a in animals:
- print a
+ print(a)
Here, you want to mark the strings in the ``animals`` list as being
translatable, but you don't actually want to translate them until they are
@@ -625,7 +625,7 @@ Here is one way you can handle this situation::
# ...
for a in animals:
- print _(a)
+ print(_(a))
This works because the dummy definition of :func:`_` simply returns the string
unchanged. And this dummy definition will temporarily override any definition
@@ -649,7 +649,7 @@ Another way to handle this is with the following example::
# ...
for a in animals:
- print _(a)
+ print(_(a))
In this case, you are marking translatable strings with the function :func:`N_`,
[#]_ which won't conflict with any definition of :func:`_`. However, you will
diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst
index af10019..1cd71ba 100644
--- a/Doc/library/heapq.rst
+++ b/Doc/library/heapq.rst
@@ -77,10 +77,10 @@ Example of use::
>>> while heap:
... ordered.append(heappop(heap))
...
- >>> print ordered
+ >>> ordered
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> data.sort()
- >>> print data == ordered
+ >>> data == ordered
True
>>>
diff --git a/Doc/library/htmlparser.rst b/Doc/library/htmlparser.rst
index 5f481d8..5cfe04e 100644
--- a/Doc/library/htmlparser.rst
+++ b/Doc/library/htmlparser.rst
@@ -171,8 +171,8 @@ As a basic example, below is a very basic HTML parser that uses the
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
- print "Encountered the beginning of a %s tag" % tag
+ print("Encountered the beginning of a %s tag" % tag)
def handle_endtag(self, tag):
- print "Encountered the end of a %s tag" % tag
+ print("Encountered the end of a %s tag" % tag)
diff --git a/Doc/library/httplib.rst b/Doc/library/httplib.rst
index badffb2..03fe681 100644
--- a/Doc/library/httplib.rst
+++ b/Doc/library/httplib.rst
@@ -475,12 +475,12 @@ Here is an example session that uses the ``GET`` method::
>>> conn = httplib.HTTPConnection("www.python.org")
>>> conn.request("GET", "/index.html")
>>> r1 = conn.getresponse()
- >>> print r1.status, r1.reason
+ >>> print(r1.status, r1.reason)
200 OK
>>> data1 = r1.read()
>>> conn.request("GET", "/parrot.spam")
>>> r2 = conn.getresponse()
- >>> print r2.status, r2.reason
+ >>> print(r2.status, r2.reason)
404 Not Found
>>> data2 = r2.read()
>>> conn.close()
@@ -494,7 +494,7 @@ Here is an example session that shows how to ``POST`` requests::
>>> conn = httplib.HTTPConnection("musi-cal.mojam.com:80")
>>> conn.request("POST", "/cgi-bin/query", params, headers)
>>> response = conn.getresponse()
- >>> print response.status, response.reason
+ >>> print(response.status, response.reason)
200 OK
>>> data = response.read()
>>> conn.close()
diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst
index 977df13..dab22e0 100644
--- a/Doc/library/imaplib.rst
+++ b/Doc/library/imaplib.rst
@@ -511,7 +511,7 @@ retrieves and prints all messages::
typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetch(num, '(RFC822)')
- print 'Message %s\n%s\n' % (num, data[0][1])
+ print('Message %s\n%s\n' % (num, data[0][1]))
M.close()
M.logout()
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index d7a7668..d6e3291 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -385,7 +385,7 @@ can be combined. ::
>>> amounts = [120.15, 764.05, 823.14]
>>> for checknum, amount in izip(count(1200), amounts):
- ... print 'Check %d is for $%.2f' % (checknum, amount)
+ ... print('Check %d is for $%.2f' % (checknum, amount))
...
Check 1200 is for $120.15
Check 1201 is for $764.05
@@ -393,7 +393,7 @@ can be combined. ::
>>> import operator
>>> for cube in imap(operator.pow, range(1,5), repeat(3)):
- ... print cube
+ ... print(cube)
...
1
8
@@ -403,7 +403,7 @@ can be combined. ::
>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura',
... '', 'martin', '', 'walter', '', 'mark']
>>> for name in islice(reportlines, 3, None, 2):
- ... print name.title()
+ ... print(name.title())
...
Alex
Laura
@@ -416,7 +416,7 @@ can be combined. ::
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(d.iteritems(), key=itemgetter(1))
>>> for k, g in groupby(di, key=itemgetter(1)):
- ... print k, map(itemgetter(0), g)
+ ... print(k, map(itemgetter(0), g))
...
1 ['a', 'c', 'e']
2 ['b', 'd', 'f']
@@ -427,7 +427,7 @@ can be combined. ::
# same group.
>>> data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28]
>>> for k, g in groupby(enumerate(data), lambda t:t[0]-t[1]):
- ... print map(operator.itemgetter(1), g)
+ ... print(map(operator.itemgetter(1), g))
...
[1]
[4, 5, 6]
diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst
index 1dac8b6..fb4bc4c 100644
--- a/Doc/library/logging.rst
+++ b/Doc/library/logging.rst
@@ -841,7 +841,7 @@ module. Here is a basic working example::
logging.basicConfig(
format="%(relativeCreated)5d %(name)-15s %(levelname)-8s %(message)s")
tcpserver = LogRecordSocketReceiver()
- print "About to start TCP server..."
+ print("About to start TCP server...")
tcpserver.serve_until_stopped()
if __name__ == "__main__":
diff --git a/Doc/library/macosa.rst b/Doc/library/macosa.rst
index 67475ed..4e0b3aa 100644
--- a/Doc/library/macosa.rst
+++ b/Doc/library/macosa.rst
@@ -31,7 +31,7 @@ In Python, the following code fragment will do the same::
import Finder
f = Finder.Finder()
- print f.get(f.window(1).name)
+ print(f.get(f.window(1).name))
As distributed the Python library includes packages that implement the standard
suites, plus packages that interface to a small number of common applications.
diff --git a/Doc/library/mailbox.rst b/Doc/library/mailbox.rst
index cfd1ebe..fc0ce8b 100644
--- a/Doc/library/mailbox.rst
+++ b/Doc/library/mailbox.rst
@@ -1620,7 +1620,7 @@ interesting::
for message in mailbox.mbox('~/mbox'):
subject = message['subject'] # Could possibly be None.
if subject and 'python' in subject.lower():
- print subject
+ print(subject)
To copy all mail from a Babyl mailbox to an MH mailbox, converting all of the
format-specific information that can be converted::
diff --git a/Doc/library/nntplib.rst b/Doc/library/nntplib.rst
index ef5a6e9..c3de3d7 100644
--- a/Doc/library/nntplib.rst
+++ b/Doc/library/nntplib.rst
@@ -20,10 +20,10 @@ about a newsgroup and print the subjects of the last 10 articles::
>>> s = NNTP('news.cwi.nl')
>>> resp, count, first, last, name = s.group('comp.lang.python')
- >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last
+ >>> print('Group', name, 'has', count, 'articles, range', first, 'to', last)
Group comp.lang.python has 59 articles, range 3742 to 3803
>>> resp, subs = s.xhdr('subject', first + '-' + last)
- >>> for id, sub in subs[-10:]: print id, sub
+ >>> for id, sub in subs[-10:]: print(id, sub)
...
3792 Re: Removing elements from a list while iterating...
3793 Re: Who likes Info files?
diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst
index bfc55f9..8809c59 100644
--- a/Doc/library/optparse.rst
+++ b/Doc/library/optparse.rst
@@ -348,7 +348,7 @@ right up against the option: since ``"-n42"`` (one argument) is equivalent to
``"-n 42"`` (two arguments), the code ::
(options, args) = parser.parse_args(["-n42"])
- print options.num
+ print(options.num)
will print ``"42"``.
@@ -646,7 +646,7 @@ Here's what :mod:`optparse`\ -based scripts usually look like::
if len(args) != 1:
parser.error("incorrect number of arguments")
if options.verbose:
- print "reading %s..." % options.filename
+ print("reading %s..." % options.filename)
[...]
if __name__ == "__main__":
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 0ad8fba..d62896b 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -1215,9 +1215,9 @@ Files and Directories
import os
from os.path import join, getsize
for root, dirs, files in os.walk('python/Lib/email'):
- print root, "consumes",
- print sum(getsize(join(root, name)) for name in files),
- print "bytes in", len(files), "non-directory files"
+ print(root, "consumes", end=" ")
+ print(sum(getsize(join(root, name)) for name in files), end=" ")
+ print("bytes in", len(files), "non-directory files")
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
diff --git a/Doc/library/pickle.rst b/Doc/library/pickle.rst
index 844e9c4..dace18a 100644
--- a/Doc/library/pickle.rst
+++ b/Doc/library/pickle.rst
@@ -574,11 +574,11 @@ Here's a silly example that *might* shed more light::
return 'My name is integer %d' % self.x
i = Integer(7)
- print i
+ print(i)
p.dump(i)
datastream = src.getvalue()
- print repr(datastream)
+ print(repr(datastream))
dst = StringIO(datastream)
up = pickle.Unpickler(dst)
@@ -597,7 +597,7 @@ Here's a silly example that *might* shed more light::
up.persistent_load = persistent_load
j = up.load()
- print j
+ print(j)
In the :mod:`cPickle` module, the unpickler's :attr:`persistent_load` attribute
can also be set to a Python list, in which case, when the unpickler reaches a
diff --git a/Doc/library/poplib.rst b/Doc/library/poplib.rst
index e9466b7..b462ec5 100644
--- a/Doc/library/poplib.rst
+++ b/Doc/library/poplib.rst
@@ -191,7 +191,7 @@ retrieves and prints all messages::
numMessages = len(M.list()[1])
for i in range(numMessages):
for j in M.retr(i+1)[1]:
- print j
+ print(j)
At the end of the module, there is a test section that contains a more extensive
example of usage.
diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst
index 3703c1c..d00caba 100644
--- a/Doc/library/pprint.rst
+++ b/Doc/library/pprint.rst
@@ -85,9 +85,10 @@ The :class:`PrettyPrinter` class supports several derivative functions:
.. function:: pprint(object[, stream[, indent[, width[, depth]]]])
Prints the formatted representation of *object* on *stream*, followed by a
- newline. If *stream* is omitted, ``sys.stdout`` is used. This may be used in
- the interactive interpreter instead of a :keyword:`print` statement for
- inspecting values. *indent*, *width* and *depth* will be passed to the
+ newline. If *stream* is omitted, ``sys.stdout`` is used. This may be used
+ in the interactive interpreter instead of the :func:`print` function for
+ inspecting values (you can even reassign ``print = pprint.pprint`` for use
+ within a scope). *indent*, *width* and *depth* will be passed to the
:class:`PrettyPrinter` constructor as formatting parameters. ::
>>> stuff = sys.path[:]
diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst
index 4fbcf77..0cbbd86 100644
--- a/Doc/library/profile.rst
+++ b/Doc/library/profile.rst
@@ -577,7 +577,7 @@ discussion in section Limitations above). ::
import profile
pr = profile.Profile()
for i in range(5):
- print pr.calibrate(10000)
+ print(pr.calibrate(10000))
The method executes the number of Python calls given by the argument, directly
and again under the profiler, measuring the time for both. It then computes the
diff --git a/Doc/library/pyexpat.rst b/Doc/library/pyexpat.rst
index cfee364..fcb7705 100644
--- a/Doc/library/pyexpat.rst
+++ b/Doc/library/pyexpat.rst
@@ -494,11 +494,11 @@ arguments. ::
# 3 handler functions
def start_element(name, attrs):
- print 'Start element:', name, attrs
+ print('Start element:', name, attrs)
def end_element(name):
- print 'End element:', name
+ print('End element:', name)
def char_data(data):
- print 'Character data:', repr(data)
+ print('Character data:', repr(data))
p = xml.parsers.expat.ParserCreate()
diff --git a/Doc/library/repr.rst b/Doc/library/repr.rst
index ae4ce65..0ad08c6 100644
--- a/Doc/library/repr.rst
+++ b/Doc/library/repr.rst
@@ -129,5 +129,5 @@ for file objects could be added::
return `obj`
aRepr = MyRepr()
- print aRepr.repr(sys.stdin) # prints '<stdin>'
+ print(aRepr.repr(sys.stdin)) # prints '<stdin>'
diff --git a/Doc/library/rlcompleter.rst b/Doc/library/rlcompleter.rst
index b882cb0..402a120 100644
--- a/Doc/library/rlcompleter.rst
+++ b/Doc/library/rlcompleter.rst
@@ -33,7 +33,7 @@ automatic :kbd:`Tab` completion::
try:
import readline
except ImportError:
- print "Module readline not available."
+ print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
diff --git a/Doc/library/sched.rst b/Doc/library/sched.rst
index bf3efbf..c262a8d 100644
--- a/Doc/library/sched.rst
+++ b/Doc/library/sched.rst
@@ -30,14 +30,14 @@ Example::
>>> import sched, time
>>> s=sched.scheduler(time.time, time.sleep)
- >>> def print_time(): print "From print_time", time.time()
+ >>> def print_time(): print("From print_time", time.time())
...
>>> def print_some_times():
- ... print time.time()
+ ... print(time.time())
... s.enter(5, 1, print_time, ())
... s.enter(10, 1, print_time, ())
... s.run()
- ... print time.time()
+ ... print(time.time())
...
>>> print_some_times()
930343690.257
diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst
index 94f305c..d3c498d 100644
--- a/Doc/library/signal.rst
+++ b/Doc/library/signal.rst
@@ -143,7 +143,7 @@ be sent, and the handler raises an exception. ::
import signal, os
def handler(signum, frame):
- print 'Signal handler called with signal', signum
+ print('Signal handler called with signal', signum)
raise IOError("Couldn't open device!")
# Set the signal handler and a 5-second alarm
diff --git a/Doc/library/simplexmlrpcserver.rst b/Doc/library/simplexmlrpcserver.rst
index ec80843..2288907 100644
--- a/Doc/library/simplexmlrpcserver.rst
+++ b/Doc/library/simplexmlrpcserver.rst
@@ -143,12 +143,12 @@ server::
import xmlrpclib
s = xmlrpclib.Server('http://localhost:8000')
- print s.pow(2,3) # Returns 2**3 = 8
- print s.add(2,3) # Returns 5
- print s.div(5,2) # Returns 5//2 = 2
+ print(s.pow(2,3)) # Returns 2**3 = 8
+ print(s.add(2,3)) # Returns 5
+ print(s.div(5,2)) # Returns 5//2 = 2
# Print list of available methods
- print s.system.listMethods()
+ print(s.system.listMethods())
CGIXMLRPCRequestHandler
diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst
index 61b90a8..3173f35 100644
--- a/Doc/library/smtplib.rst
+++ b/Doc/library/smtplib.rst
@@ -317,7 +317,7 @@ example doesn't do any processing of the :rfc:`822` headers. In particular, the
fromaddr = prompt("From: ")
toaddrs = prompt("To: ").split()
- print "Enter message, end with ^D (Unix) or ^Z (Windows):"
+ print("Enter message, end with ^D (Unix) or ^Z (Windows):")
# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\n\r\n"
@@ -331,7 +331,7 @@ example doesn't do any processing of the :rfc:`822` headers. In particular, the
break
msg = msg + line
- print "Message length is " + repr(len(msg))
+ print("Message length is", len(msg))
server = smtplib.SMTP('localhost')
server.set_debuglevel(1)
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index f4265b4..a445b54 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -730,7 +730,7 @@ The first two examples support IPv4 only. ::
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
- print 'Connected by', addr
+ print('Connected by', addr)
while 1:
data = conn.recv(1024)
if not data: break
@@ -749,7 +749,7 @@ The first two examples support IPv4 only. ::
s.send('Hello, world')
data = s.recv(1024)
s.close()
- print 'Received', repr(data)
+ print('Received', repr(data))
The next two examples are identical to the above two, but support both IPv4 and
IPv6. The server side will listen to the first address family available (it
@@ -781,10 +781,10 @@ sends traffic to the first one connected successfully. ::
continue
break
if s is None:
- print 'could not open socket'
+ print('could not open socket')
sys.exit(1)
conn, addr = s.accept()
- print 'Connected by', addr
+ print('Connected by', addr)
while 1:
data = conn.recv(1024)
if not data: break
@@ -815,10 +815,10 @@ sends traffic to the first one connected successfully. ::
continue
break
if s is None:
- print 'could not open socket'
+ print('could not open socket')
sys.exit(1)
s.send('Hello, world')
data = s.recv(1024)
s.close()
- print 'Received', repr(data)
+ print('Received', repr(data))
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index b12184c..514c71e 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -79,7 +79,7 @@ This example uses the iterator form::
>>> c = conn.cursor()
>>> c.execute('select * from stocks order by price')
>>> for row in c:
- ... print row
+ ... print(row)
...
(u'2006-01-05', u'BUY', u'RHAT', 100, 35.140000000000001)
(u'2006-03-28', u'BUY', u'IBM', 1000, 45.0)
diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
index 55ff7cd..5072caf 100644
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -297,8 +297,8 @@ sends some bytes, and reads part of the response::
ssl_sock.connect(('www.verisign.com', 443))
- print repr(ssl_sock.getpeername())
- print pprint.pformat(ssl_sock.getpeercert())
+ print(repr(ssl_sock.getpeername()))
+ pprint.pprint(ssl_sock.getpeercert())
# Set a simple HTTP request -- use httplib in actual code.
ssl_sock.write("""GET / HTTP/1.0\r
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index 3e049b2..17962c2 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -22,8 +22,6 @@ interpreter.
The principal built-in types are numerics, sequences, mappings, files, classes,
instances and exceptions.
-.. index:: statement: print
-
Some operations are supported by several object types; in particular,
practically all objects can be compared, tested for truth value, and converted
to a string (with the :func:`repr` function or the slightly different
@@ -1976,7 +1974,7 @@ Files have the following methods:
A file object is its own iterator, for example ``iter(f)`` returns *f* (unless
*f* is closed). When a file is used as an iterator, typically in a
- :keyword:`for` loop (for example, ``for line in f: print line``), the
+ :keyword:`for` loop (for example, ``for line in f: print(line)``), the
:meth:`__next__` method is called repeatedly. This method returns the next
input line, or raises :exc:`StopIteration` when EOF is hit when the file is open
for reading (behavior is undefined when the file is open for writing). In order
@@ -2133,23 +2131,6 @@ the particular object.
mode the value of this attribute will be ``None``.
-.. attribute:: file.softspace
-
- Boolean that indicates whether a space character needs to be printed before
- another value when using the :keyword:`print` statement. Classes that are trying
- to simulate a file object should also have a writable :attr:`softspace`
- attribute, which should be initialized to zero. This will be automatic for most
- classes implemented in Python (care may be needed for objects that override
- attribute access); types implemented in C will have to provide a writable
- :attr:`softspace` attribute.
-
- .. note::
-
- This attribute is not used to control the :keyword:`print` statement, but to
- allow the implementation of :keyword:`print` to keep track of its internal
- state.
-
-
.. _typecontextmanager:
Context Manager Types
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index c2a0a6e..6f1aaff 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -495,7 +495,7 @@ always available.
File objects corresponding to the interpreter's standard input, output and error
streams. ``stdin`` is used for all interpreter input except for scripts.
- ``stdout`` is used for the output of :keyword:`print` and expression statements.
+ ``stdout`` is used for the output of :func:`print` and expression statements.
The interpreter's own prompts and (almost all of) its error messages go to
``stderr``. ``stdout`` and ``stderr`` needn't be built-in file objects: any
object is acceptable as long as it has a :meth:`write` method that takes a
diff --git a/Doc/library/tabnanny.rst b/Doc/library/tabnanny.rst
index 7632b02..4402e78 100644
--- a/Doc/library/tabnanny.rst
+++ b/Doc/library/tabnanny.rst
@@ -26,9 +26,9 @@ described below.
If *file_or_dir* is a directory and not a symbolic link, then recursively
descend the directory tree named by *file_or_dir*, checking all :file:`.py`
- files along the way. If *file_or_dir* is an ordinary Python source file, it is
- checked for whitespace related problems. The diagnostic messages are written to
- standard output using the print statement.
+ files along the way. If *file_or_dir* is an ordinary Python source file, it
+ is checked for whitespace related problems. The diagnostic messages are
+ written to standard output using the :func:`print` function.
.. data:: verbose
diff --git a/Doc/library/tokenize.rst b/Doc/library/tokenize.rst
index 61b8497..0359f84 100644
--- a/Doc/library/tokenize.rst
+++ b/Doc/library/tokenize.rst
@@ -90,9 +90,9 @@ objects::
"""Substitute Decimals for floats in a string of statements.
>>> from decimal import Decimal
- >>> s = 'print +21.3e-5*-.1234/81.7'
+ >>> s = 'print(+21.3e-5*-.1234/81.7)'
>>> decistmt(s)
- "print +Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7')"
+ "print(+Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7'))"
>>> exec(s)
-3.21716034272e-007