mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-10 19:16:34 +03:00
docs: drop use of print statement, use the print() function instead
Close #1556
This commit is contained in:
parent
0b01ded426
commit
638be85eb6
|
@ -226,7 +226,7 @@ read:
|
|||
|
||||
>>> cur.execute("SELECT '(10.2,20.3)'::point")
|
||||
>>> point = cur.fetchone()[0]
|
||||
>>> print type(point), point.x, point.y
|
||||
>>> print(type(point), point.x, point.y)
|
||||
<class 'Point'> 10.2 20.3
|
||||
|
||||
A typecaster created by `!new_type()` can be also used with
|
||||
|
@ -284,15 +284,15 @@ something to read::
|
|||
curs = conn.cursor()
|
||||
curs.execute("LISTEN test;")
|
||||
|
||||
print "Waiting for notifications on channel 'test'"
|
||||
print("Waiting for notifications on channel 'test'")
|
||||
while True:
|
||||
if select.select([conn],[],[],5) == ([],[],[]):
|
||||
print "Timeout"
|
||||
print("Timeout")
|
||||
else:
|
||||
conn.poll()
|
||||
while conn.notifies:
|
||||
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'`
|
||||
in a separate :program:`psql` shell, the output may look similar to:
|
||||
|
|
|
@ -292,7 +292,7 @@ The ``cursor`` class
|
|||
|
||||
>>> cur.execute("SELECT * FROM test;")
|
||||
>>> for record in cur:
|
||||
... print record
|
||||
... print(record)
|
||||
...
|
||||
(1, 100, "abc'def")
|
||||
(2, None, 'dada')
|
||||
|
|
|
@ -168,7 +168,7 @@ available through the following exceptions:
|
|||
|
||||
>>> e.pgcode
|
||||
'42P01'
|
||||
>>> print e.pgerror
|
||||
>>> print(e.pgerror)
|
||||
ERROR: relation "barf" does not exist
|
||||
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
|
||||
`~psycopg2.extensions.encodings` mapping)::
|
||||
|
||||
>>> print u, type(u)
|
||||
>>> print(u, type(u))
|
||||
àèìòù€ <type 'unicode'>
|
||||
|
||||
>>> 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
|
||||
usually 8 bit `!str` objects encoded in the database client encoding::
|
||||
|
||||
>>> print conn.encoding
|
||||
>>> print(conn.encoding)
|
||||
UTF8
|
||||
|
||||
>>> cur.execute("SELECT data FROM test WHERE num = 74")
|
||||
>>> 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'
|
||||
|
||||
>>> conn.set_client_encoding('LATIN9')
|
||||
|
||||
>>> cur.execute("SELECT data FROM test WHERE num = 74")
|
||||
>>> x = cur.fetchone()[0]
|
||||
>>> print type(x), repr(x)
|
||||
>>> print(type(x), repr(x))
|
||||
<type 'str'> '\xe0\xe8\xec\xf2\xf9\xa4'
|
||||
|
||||
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")
|
||||
>>> 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'
|
||||
|
||||
In the above example, the `~psycopg2.extensions.UNICODE` typecaster is
|
||||
|
|
Loading…
Reference in New Issue
Block a user