mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 10:23:43 +03:00
docs: drop use of print statement, use the print() function instead
Close #1556
This commit is contained in:
parent
0b01ded426
commit
638be85eb6
|
@ -8,7 +8,7 @@ check: doctest
|
||||||
# It is not clean by 'make clean'
|
# It is not clean by 'make clean'
|
||||||
|
|
||||||
PYTHON := python$(PYTHON_VERSION)
|
PYTHON := python$(PYTHON_VERSION)
|
||||||
PYTHON_VERSION ?= $(shell $(PYTHON) -c 'import sys; print ("%d.%d" % sys.version_info[:2])')
|
PYTHON_VERSION ?= $(shell $(PYTHON) -c 'import sys; print("%d.%d" % sys.version_info[:2])')
|
||||||
BUILD_DIR = $(shell pwd)/../build/lib.$(PYTHON_VERSION)
|
BUILD_DIR = $(shell pwd)/../build/lib.$(PYTHON_VERSION)
|
||||||
|
|
||||||
SPHINXBUILD ?= $$(pwd)/env/bin/sphinx-build
|
SPHINXBUILD ?= $$(pwd)/env/bin/sphinx-build
|
||||||
|
|
|
@ -226,7 +226,7 @@ read:
|
||||||
|
|
||||||
>>> cur.execute("SELECT '(10.2,20.3)'::point")
|
>>> cur.execute("SELECT '(10.2,20.3)'::point")
|
||||||
>>> point = cur.fetchone()[0]
|
>>> point = cur.fetchone()[0]
|
||||||
>>> print type(point), point.x, point.y
|
>>> print(type(point), point.x, point.y)
|
||||||
<class 'Point'> 10.2 20.3
|
<class 'Point'> 10.2 20.3
|
||||||
|
|
||||||
A typecaster created by `!new_type()` can be also used with
|
A typecaster created by `!new_type()` can be also used with
|
||||||
|
@ -284,15 +284,15 @@ something to read::
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
curs.execute("LISTEN test;")
|
curs.execute("LISTEN test;")
|
||||||
|
|
||||||
print "Waiting for notifications on channel 'test'"
|
print("Waiting for notifications on channel 'test'")
|
||||||
while True:
|
while True:
|
||||||
if select.select([conn],[],[],5) == ([],[],[]):
|
if select.select([conn],[],[],5) == ([],[],[]):
|
||||||
print "Timeout"
|
print("Timeout")
|
||||||
else:
|
else:
|
||||||
conn.poll()
|
conn.poll()
|
||||||
while conn.notifies:
|
while conn.notifies:
|
||||||
notify = conn.notifies.pop(0)
|
notify = conn.notifies.pop(0)
|
||||||
print "Got NOTIFY:", notify.pid, notify.channel, notify.payload
|
print("Got NOTIFY:", notify.pid, notify.channel, notify.payload)
|
||||||
|
|
||||||
Running the script and executing a command such as :sql:`NOTIFY test, 'hello'`
|
Running the script and executing a command such as :sql:`NOTIFY test, 'hello'`
|
||||||
in a separate :program:`psql` shell, the output may look similar to:
|
in a separate :program:`psql` shell, the output may look similar to:
|
||||||
|
|
|
@ -292,7 +292,7 @@ The ``cursor`` class
|
||||||
|
|
||||||
>>> cur.execute("SELECT * FROM test;")
|
>>> cur.execute("SELECT * FROM test;")
|
||||||
>>> for record in cur:
|
>>> for record in cur:
|
||||||
... print record
|
... print(record)
|
||||||
...
|
...
|
||||||
(1, 100, "abc'def")
|
(1, 100, "abc'def")
|
||||||
(2, None, 'dada')
|
(2, None, 'dada')
|
||||||
|
|
|
@ -168,7 +168,7 @@ available through the following exceptions:
|
||||||
|
|
||||||
>>> e.pgcode
|
>>> e.pgcode
|
||||||
'42P01'
|
'42P01'
|
||||||
>>> print e.pgerror
|
>>> print(e.pgerror)
|
||||||
ERROR: relation "barf" does not exist
|
ERROR: relation "barf" does not exist
|
||||||
LINE 1: SELECT * FROM barf
|
LINE 1: SELECT * FROM barf
|
||||||
^
|
^
|
||||||
|
|
|
@ -407,7 +407,7 @@ defined on the database connection (the `PostgreSQL encoding`__, available in
|
||||||
`connection.encoding`, is translated into a `Python encoding`__ using the
|
`connection.encoding`, is translated into a `Python encoding`__ using the
|
||||||
`~psycopg2.extensions.encodings` mapping)::
|
`~psycopg2.extensions.encodings` mapping)::
|
||||||
|
|
||||||
>>> print u, type(u)
|
>>> print(u, type(u))
|
||||||
àèìòù€ <type 'unicode'>
|
àèìòù€ <type 'unicode'>
|
||||||
|
|
||||||
>>> cur.execute("INSERT INTO test (num, data) VALUES (%s,%s);", (74, u))
|
>>> cur.execute("INSERT INTO test (num, data) VALUES (%s,%s);", (74, u))
|
||||||
|
@ -418,19 +418,19 @@ defined on the database connection (the `PostgreSQL encoding`__, available in
|
||||||
When reading data from the database, in Python 2 the strings returned are
|
When reading data from the database, in Python 2 the strings returned are
|
||||||
usually 8 bit `!str` objects encoded in the database client encoding::
|
usually 8 bit `!str` objects encoded in the database client encoding::
|
||||||
|
|
||||||
>>> print conn.encoding
|
>>> print(conn.encoding)
|
||||||
UTF8
|
UTF8
|
||||||
|
|
||||||
>>> cur.execute("SELECT data FROM test WHERE num = 74")
|
>>> cur.execute("SELECT data FROM test WHERE num = 74")
|
||||||
>>> x = cur.fetchone()[0]
|
>>> x = cur.fetchone()[0]
|
||||||
>>> print x, type(x), repr(x)
|
>>> print(x, type(x), repr(x))
|
||||||
àèìòù€ <type 'str'> '\xc3\xa0\xc3\xa8\xc3\xac\xc3\xb2\xc3\xb9\xe2\x82\xac'
|
àèìòù€ <type 'str'> '\xc3\xa0\xc3\xa8\xc3\xac\xc3\xb2\xc3\xb9\xe2\x82\xac'
|
||||||
|
|
||||||
>>> conn.set_client_encoding('LATIN9')
|
>>> conn.set_client_encoding('LATIN9')
|
||||||
|
|
||||||
>>> cur.execute("SELECT data FROM test WHERE num = 74")
|
>>> cur.execute("SELECT data FROM test WHERE num = 74")
|
||||||
>>> x = cur.fetchone()[0]
|
>>> x = cur.fetchone()[0]
|
||||||
>>> print type(x), repr(x)
|
>>> print(type(x), repr(x))
|
||||||
<type 'str'> '\xe0\xe8\xec\xf2\xf9\xa4'
|
<type 'str'> '\xe0\xe8\xec\xf2\xf9\xa4'
|
||||||
|
|
||||||
In Python 3 instead the strings are automatically *decoded* in the connection
|
In Python 3 instead the strings are automatically *decoded* in the connection
|
||||||
|
@ -442,7 +442,7 @@ In Python 2 you must register a :ref:`typecaster
|
||||||
|
|
||||||
>>> cur.execute("SELECT data FROM test WHERE num = 74")
|
>>> cur.execute("SELECT data FROM test WHERE num = 74")
|
||||||
>>> x = cur.fetchone()[0]
|
>>> x = cur.fetchone()[0]
|
||||||
>>> print x, type(x), repr(x)
|
>>> print(x, type(x), repr(x))
|
||||||
àèìòù€ <type 'unicode'> u'\xe0\xe8\xec\xf2\xf9\u20ac'
|
àèìòù€ <type 'unicode'> u'\xe0\xe8\xec\xf2\xf9\u20ac'
|
||||||
|
|
||||||
In the above example, the `~psycopg2.extensions.UNICODE` typecaster is
|
In the above example, the `~psycopg2.extensions.UNICODE` typecaster is
|
||||||
|
|
Loading…
Reference in New Issue
Block a user