Convert all print statements in the docs. · python/cpython@6911e3c · GitHub
Skip to content

Commit 6911e3c

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

71 files changed

Lines changed: 351 additions & 388 deletions

Some content is hidden

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

Doc/c-api/abstract.rst

Lines changed: 2 additions & 2 deletions

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

0 commit comments

Comments
 (0)