diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2023-04-17 20:07:17 +0200 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2023-04-17 20:07:17 +0200 |
commit | 638be85eb6f823f2ed1b8a58cbf390981c670f46 (patch) | |
tree | c295a318cb551f96271bf3f49096b628018191a8 | |
parent | 0b01ded426b7423621af68d9fc33e532a5bda4a7 (diff) | |
download | psycopg2-638be85eb6f823f2ed1b8a58cbf390981c670f46.tar.gz |
docs: drop use of print statement, use the print() function instead
Close #1556
-rw-r--r-- | doc/Makefile | 2 | ||||
-rw-r--r-- | doc/src/advanced.rst | 8 | ||||
-rw-r--r-- | doc/src/cursor.rst | 2 | ||||
-rw-r--r-- | doc/src/module.rst | 2 | ||||
-rw-r--r-- | doc/src/usage.rst | 10 |
5 files changed, 12 insertions, 12 deletions
diff --git a/doc/Makefile b/doc/Makefile index 789a8e6..1f780d4 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -8,7 +8,7 @@ check: doctest # It is not clean by 'make clean' 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) SPHINXBUILD ?= $$(pwd)/env/bin/sphinx-build diff --git a/doc/src/advanced.rst b/doc/src/advanced.rst index 28c4be9..eb3b54b 100644 --- a/doc/src/advanced.rst +++ b/doc/src/advanced.rst @@ -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: diff --git a/doc/src/cursor.rst b/doc/src/cursor.rst index a998b3c..eee376e 100644 --- a/doc/src/cursor.rst +++ b/doc/src/cursor.rst @@ -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') diff --git a/doc/src/module.rst b/doc/src/module.rst index f17f3ae..821fd3c 100644 --- a/doc/src/module.rst +++ b/doc/src/module.rst @@ -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 ^ diff --git a/doc/src/usage.rst b/doc/src/usage.rst index f469093..2bf2448 100644 --- a/doc/src/usage.rst +++ b/doc/src/usage.rst @@ -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 |