Skip to content

Commit 6911e3c

Browse files
committed
Convert all print statements in the docs.
1 parent c987924 commit 6911e3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+351
-388
lines changed

Doc/c-api/abstract.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ Object Protocol
143143

144144
Compute a string representation of object *o*. Returns the string
145145
representation on success, *NULL* on failure. This is the equivalent of the
146-
Python expression ``str(o)``. Called by the :func:`str` built-in function and
147-
by the :keyword:`print` statement.
146+
Python expression ``str(o)``. Called by the :func:`str` built-in function
147+
and, therefore, by the :func:`print` function.
148148

149149

150150
.. cfunction:: PyObject* PyObject_Unicode(PyObject *o)

Doc/c-api/newtypes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ type objects) *must* have the :attr:`ob_size` field.
645645

646646
The signature is the same as for :cfunc:`PyObject_Str`; it must return a string
647647
or a Unicode object. This function should return a "friendly" string
648-
representation of the object, as this is the representation that will be used by
649-
the print statement.
648+
representation of the object, as this is the representation that will be used,
649+
among other things, by the :func:`print` function.
650650

651651
When this field is not set, :cfunc:`PyObject_Repr` is called to return a string
652652
representation.

Doc/extending/embedding.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ perform some operation on a file. ::
6464
{
6565
Py_Initialize();
6666
PyRun_SimpleString("from time import time,ctime\n"
67-
"print 'Today is',ctime(time())\n");
67+
"print('Today is', ctime(time()))\n");
6868
Py_Finalize();
6969
return 0;
7070
}
@@ -141,7 +141,7 @@ array. If you compile and link this program (let's call the finished executable
141141
:program:`call`), and use it to execute a Python script, such as::
142142

143143
def multiply(a,b):
144-
print "Will compute", a, "times", b
144+
print("Will compute", a, "times", b)
145145
c = 0
146146
for i in range(0, a):
147147
c = c + b
@@ -234,7 +234,7 @@ These two lines initialize the ``numargs`` variable, and make the
234234
With these extensions, the Python script can do things like ::
235235

236236
import emb
237-
print "Number of arguments", emb.numargs()
237+
print("Number of arguments", emb.numargs())
238238

239239
In a real application, the methods will expose an API of the application to
240240
Python.

Doc/extending/newtypes.rst

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,11 @@ increases an internal counter. ::
826826
>>> import shoddy
827827
>>> s = shoddy.Shoddy(range(3))
828828
>>> s.extend(s)
829-
>>> print len(s)
829+
>>> print(len(s))
830830
6
831-
>>> print s.increment()
831+
>>> print(s.increment())
832832
1
833-
>>> print s.increment()
833+
>>> print(s.increment())
834834
2
835835

836836
.. literalinclude:: ../includes/shoddy.c
@@ -1063,34 +1063,6 @@ Here is a simple example::
10631063
obj->obj_UnderlyingDatatypePtr->size);
10641064
}
10651065

1066-
The print function will be called whenever Python needs to "print" an instance
1067-
of the type. For example, if 'node' is an instance of type TreeNode, then the
1068-
print function is called when Python code calls::
1069-
1070-
print node
1071-
1072-
There is a flags argument and one flag, :const:`Py_PRINT_RAW`, and it suggests
1073-
that you print without string quotes and possibly without interpreting escape
1074-
sequences.
1075-
1076-
The print function receives a file object as an argument. You will likely want
1077-
to write to that file object.
1078-
1079-
Here is a sample print function::
1080-
1081-
static int
1082-
newdatatype_print(newdatatypeobject *obj, FILE *fp, int flags)
1083-
{
1084-
if (flags & Py_PRINT_RAW) {
1085-
fprintf(fp, "<{newdatatype object--size: %d}>",
1086-
obj->obj_UnderlyingDatatypePtr->size);
1087-
}
1088-
else {
1089-
fprintf(fp, "\"<{newdatatype object--size: %d}>\"",
1090-
obj->obj_UnderlyingDatatypePtr->size);
1091-
}
1092-
return 0;
1093-
}
10941066

10951067

10961068
Attribute Management

Doc/howto/doanddont.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ its least useful properties.
5959

6060
Remember, you can never know for sure what names a module exports, so either
6161
take what you need --- ``from module import name1, name2``, or keep them in the
62-
module and access on a per-need basis --- ``import module;print module.name``.
62+
module and access on a per-need basis --- ``import module; print(module.name)``.
6363

6464

6565
When It Is Just Fine
@@ -181,7 +181,7 @@ The following is a very popular anti-idiom ::
181181

182182
def get_status(file):
183183
if not os.path.exists(file):
184-
print "file not found"
184+
print("file not found")
185185
sys.exit(1)
186186
return open(file).readline()
187187

@@ -199,7 +199,7 @@ Here is a better way to do it. ::
199199
try:
200200
return open(file).readline()
201201
except (IOError, OSError):
202-
print "file not found"
202+
print("file not found")
203203
sys.exit(1)
204204

205205
In this version, \*either\* the file gets opened and the line is read (so it
@@ -264,12 +264,13 @@ More useful functions in :mod:`os.path`: :func:`basename`, :func:`dirname` and
264264
There are also many useful builtin functions people seem not to be aware of for
265265
some reason: :func:`min` and :func:`max` can find the minimum/maximum of any
266266
sequence with comparable semantics, for example, yet many people write their own
267-
:func:`max`/:func:`min`. Another highly useful function is :func:`reduce`. A
268-
classical use of :func:`reduce` is something like ::
267+
:func:`max`/:func:`min`. Another highly useful function is
268+
:func:`functools.reduce`. A classical use of :func:`reduce` is something like
269+
::
269270

270-
import sys, operator
271+
import sys, operator, functools
271272
nums = map(float, sys.argv[1:])
272-
print reduce(operator.add, nums)/len(nums)
273+
print(functools.reduce(operator.add, nums) / len(nums))
273274

274275
This cute little script prints the average of all numbers given on the command
275276
line. The :func:`reduce` adds up all the numbers, and the rest is just some

Doc/howto/functional.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ You can experiment with the iteration interface manually::
201201

202202
>>> L = [1,2,3]
203203
>>> it = iter(L)
204-
>>> print it
204+
>>> it
205205
<iterator object at 0x8116870>
206206
>>> it.next()
207207
1
@@ -221,10 +221,10 @@ be an iterator or some object for which ``iter()`` can create an iterator.
221221
These two statements are equivalent::
222222

223223
for i in iter(obj):
224-
print i
224+
print(i)
225225

226226
for i in obj:
227-
print i
227+
print(i)
228228

229229
Iterators can be materialized as lists or tuples by using the :func:`list` or
230230
:func:`tuple` constructor functions::
@@ -274,7 +274,7 @@ dictionary's keys::
274274
>>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
275275
... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
276276
>>> for key in m:
277-
... print key, m[key]
277+
... print(key, m[key])
278278
Mar 3
279279
Feb 2
280280
Aug 8
@@ -316,7 +316,7 @@ elements::
316316

317317
S = set((2, 3, 5, 7, 11, 13))
318318
for i in S:
319-
print i
319+
print(i)
320320

321321

322322

@@ -568,18 +568,18 @@ the internal counter.
568568
And here's an example of changing the counter:
569569

570570
>>> it = counter(10)
571-
>>> print it.next()
571+
>>> it.next()
572572
0
573-
>>> print it.next()
573+
>>> it.next()
574574
1
575-
>>> print it.send(8)
575+
>>> it.send(8)
576576
8
577-
>>> print it.next()
577+
>>> it.next()
578578
9
579-
>>> print it.next()
579+
>>> it.next()
580580
Traceback (most recent call last):
581581
File ``t.py'', line 15, in ?
582-
print it.next()
582+
it.next()
583583
StopIteration
584584

585585
Because ``yield`` will often be returning ``None``, you should always check for
@@ -721,7 +721,7 @@ indexes at which certain conditions are met::
721721
f = open('data.txt', 'r')
722722
for i, line in enumerate(f):
723723
if line.strip() == '':
724-
print 'Blank line at line #%i' % i
724+
print('Blank line at line #%i' % i)
725725

726726
``sorted(iterable, [cmp=None], [key=None], [reverse=False)`` collects all the
727727
elements of the iterable into a list, sorts the list, and returns the sorted
@@ -1100,7 +1100,7 @@ Here's a small but realistic example::
11001100

11011101
def log (message, subsystem):
11021102
"Write the contents of 'message' to the specified subsystem."
1103-
print '%s: %s' % (subsystem, message)
1103+
print('%s: %s' % (subsystem, message))
11041104
...
11051105

11061106
server_log = functools.partial(log, subsystem='server')
@@ -1395,6 +1395,6 @@ features in Python 2.5.
13951395
for elem in slice[:-1]:
13961396
sys.stdout.write(str(elem))
13971397
sys.stdout.write(', ')
1398-
print elem[-1]
1398+
print(elem[-1])
13991399
14001400

0 commit comments

Comments
 (0)