Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61fed9c

Browse files
committed
Merge from 3.2
2 parents b6032f5 + cc809a2 commit 61fed9c

2 files changed

Lines changed: 17 additions & 48 deletions

File tree

Doc/faq/extending.rst

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ many other useful protocols.
9999
How do I use Py_BuildValue() to create a tuple of arbitrary length?
100100
-------------------------------------------------------------------
101101

102-
You can't. Use ``t = PyTuple_New(n)`` instead, and fill it with objects using
103-
``PyTuple_SetItem(t, i, o)`` -- note that this "eats" a reference count of
104-
``o``, so you have to :c:func:`Py_INCREF` it. Lists have similar functions
105-
``PyList_New(n)`` and ``PyList_SetItem(l, i, o)``. Note that you *must* set all
106-
the tuple items to some value before you pass the tuple to Python code --
107-
``PyTuple_New(n)`` initializes them to NULL, which isn't a valid Python value.
102+
You can't. Use :c:func:`PyTuple_Pack` instead.
108103

109104

110105
How do I call an object's method from C?
@@ -147,21 +142,30 @@ this object to :data:`sys.stdout` and :data:`sys.stderr`. Call print_error, or
147142
just allow the standard traceback mechanism to work. Then, the output will go
148143
wherever your ``write()`` method sends it.
149144

150-
The easiest way to do this is to use the StringIO class in the standard library.
145+
The easiest way to do this is to use the :class:`io.StringIO` class::
151146

152-
Sample code and use for catching stdout:
147+
>>> import io, sys
148+
>>> sys.stdout = io.StringIO()
149+
>>> print('foo')
150+
>>> print('hello world!')
151+
>>> sys.stderr.write(sys.stdout.getvalue())
152+
foo
153+
hello world!
154+
155+
A custom object to do the same would look like this::
153156

154-
>>> class StdoutCatcher:
157+
>>> import io, sys
158+
>>> class StdoutCatcher(io.TextIOBase):
155159
... def __init__(self):
156-
... self.data = ''
160+
... self.data = []
157161
... def write(self, stuff):
158-
... self.data = self.data + stuff
162+
... self.data.append(stuff)
159163
...
160164
>>> import sys
161165
>>> sys.stdout = StdoutCatcher()
162166
>>> print('foo')
163167
>>> print('hello world!')
164-
>>> sys.stderr.write(sys.stdout.data)
168+
>>> sys.stderr.write(''.join(sys.stdout.data))
165169
foo
166170
hello world!
167171

Doc/faq/general.rst

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It has interfaces to many system calls and libraries, as well as to various
1919
window systems, and is extensible in C or C++. It is also usable as an
2020
extension language for applications that need a programmable interface.
2121
Finally, Python is portable: it runs on many Unix variants, on the Mac, and on
22-
PCs under MS-DOS, Windows, Windows NT, and OS/2.
22+
Windows 2000 and later.
2323

2424
To find out more, start with :ref:`tutorial-index`. The `Beginner's Guide to
2525
Python <http://wiki.python.org/moin/BeginnersGuide>`_ links to other
@@ -469,38 +469,3 @@ http://www.python.org/editors/ for a full list of Python editing environments.
469469
If you want to discuss Python's use in education, you may be interested in
470470
joining `the edu-sig mailing list
471471
<http://python.org/community/sigs/current/edu-sig>`_.
472-
473-
474-
Upgrading Python
475-
================
476-
477-
What is this bsddb185 module my application keeps complaining about?
478-
--------------------------------------------------------------------
479-
480-
.. XXX remove this question?
481-
482-
Starting with Python2.3, the distribution includes the `PyBSDDB package
483-
<http://pybsddb.sf.net/>` as a replacement for the old bsddb module. It
484-
includes functions which provide backward compatibility at the API level, but
485-
requires a newer version of the underlying `Berkeley DB
486-
<http://www.sleepycat.com>`_ library. Files created with the older bsddb module
487-
can't be opened directly using the new module.
488-
489-
Using your old version of Python and a pair of scripts which are part of Python
490-
2.3 (db2pickle.py and pickle2db.py, in the Tools/scripts directory) you can
491-
convert your old database files to the new format. Using your old Python
492-
version, run the db2pickle.py script to convert it to a pickle, e.g.::
493-
494-
python2.2 <pathto>/db2pickley.py database.db database.pck
495-
496-
Rename your database file::
497-
498-
mv database.db olddatabase.db
499-
500-
Now convert the pickle file to a new format database::
501-
502-
python <pathto>/pickle2db.py database.db database.pck
503-
504-
The precise commands you use will vary depending on the particulars of your
505-
installation. For full details about operation of these two scripts check the
506-
doc string at the start of each one.

0 commit comments

Comments
 (0)