Skip to content

Commit 9e03127

Browse files
authored
print() is a function in Python 3 (#98)
1 parent c739b59 commit 9e03127

File tree

11 files changed

+40
-29
lines changed

11 files changed

+40
-29
lines changed

demo/btrfs-snap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
creates a exactly named snapshots and bails out if they exist
55
"""
6+
from __future__ import print_function
67

78
import argparse
89
import fcntl
@@ -47,6 +48,6 @@
4748
try:
4849
fcntl.ioctl(target, lib.BTRFS_IOC_SNAP_CREATE_V2, args_buffer)
4950
except IOError as e:
50-
print e
51+
print(e)
5152
sys.exit(1)
5253

demo/extern_python_varargs.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import cffi
23

34
ffi = cffi.FFI()
@@ -46,16 +47,16 @@ def f(n, va):
4647
x = lib.fetch_int(va)
4748
y = lib.fetch_int(va)
4849
z = lib.fetch_int(va)
49-
print (x, y, z)
50+
print(x, y, z)
5051
elif n == 1:
5152
ptr = lib.fetch_ptr(va)
52-
print 'ptr to:', ffi.cast("int *", ptr)[0]
53+
print('ptr to:', ffi.cast("int *", ptr)[0])
5354
elif n == 2:
5455
x = lib.fetch_double(va)
5556
y = lib.fetch_double(va)
56-
print (x, y)
57+
print(x, y)
5758
else:
5859
raise AssertionError(n)
5960
return 14
6061

61-
print lib.my_algo(10)
62+
print(lib.my_algo(10))

demo/fastcsv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import csv
23
import cffi
34

@@ -263,4 +264,4 @@ def fastcsv_reader(f, dialect_name):
263264
with open('/etc/passwd', 'rb') as f:
264265
reader = fastcsv_reader(f, 'unixpwd')
265266
for row in reader:
266-
print row
267+
print(row)

demo/gmp.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import sys
23
#
34
# This is only a demo based on the GMP library.
@@ -8,7 +9,7 @@
89
try:
910
from _gmp_cffi import ffi, lib
1011
except ImportError:
11-
print 'run gmp_build first, then make sure the shared object is on sys.path'
12+
print('run gmp_build first, then make sure the shared object is on sys.path')
1213
sys.exit(1)
1314

1415
# ffi "knows" about the declared variables and functions from the
@@ -22,12 +23,12 @@
2223
b = ffi.new("mpz_t")
2324

2425
if len(sys.argv) < 3:
25-
print 'call as %s bigint1, bigint2' % sys.argv[0]
26+
print('call as %s bigint1, bigint2' % sys.argv[0])
2627
sys.exit(2)
2728

2829
lib.mpz_init_set_str(a, sys.argv[1], 10) # Assume decimal integers
2930
lib.mpz_init_set_str(b, sys.argv[2], 10) # Assume decimal integers
3031
lib.mpz_add(a, a, b) # a=a+b
3132

3233
s = lib.mpz_get_str(ffi.NULL, 10, a)
33-
print ffi.string(s)
34+
print(ffi.string(s))

demo/manual2.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import _cffi_backend
23

34
ffi = _cffi_backend.FFI(b"manual2",
@@ -19,16 +20,16 @@
1920
x = lib.close(-42)
2021
assert x == -1
2122

22-
print lib.stdout
23+
print(lib.stdout)
2324

24-
print ffi.new("struct point_s *")
25-
print ffi.offsetof("struct point_s", "x")
26-
print ffi.offsetof("struct point_s", "y")
27-
print ffi.new("struct point_s[CC]")
25+
print(ffi.new("struct point_s *"))
26+
print(ffi.offsetof("struct point_s", "x"))
27+
print(ffi.offsetof("struct point_s", "y"))
28+
print(ffi.new("struct point_s[CC]"))
2829
assert ffi.sizeof("struct point_s[CC]") == 2 * ffi.sizeof("struct point_s")
2930

30-
print ffi.cast("enum myenum_e", 2)
31-
print ffi.cast("myint_t", -2)
31+
print(ffi.cast("enum myenum_e", 2))
32+
print(ffi.cast("myint_t", -2))
3233
assert ffi.typeof("myint_t") == ffi.typeof("int")
3334

3435
del ffi, lib

demo/pwuid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from __future__ import print_function
12
import sys, os
23

34
# run pwuid_build first, then make sure the shared object is on sys.path
45
from _pwuid_cffi import ffi, lib
56

67

7-
print ffi.string(lib.getpwuid(0).pw_name)
8+
print(ffi.string(lib.getpwuid(0).pw_name))

demo/pyobj.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12

23
referents = [] # list "object descriptor -> python object"
34
freelist = None
@@ -116,9 +117,9 @@ def pyobj_add(p1, p2):
116117
""")
117118

118119
with Ref([10, 20, 30, 40]) as p_list:
119-
print lib.sum_integers(p_list)
120+
print(lib.sum_integers(p_list))
120121
with Ref(5) as p_initial:
121122
result = discard(lib.sum_objects(p_list, p_initial))
122-
print result
123+
print(result)
123124

124125
assert count_pyobj_alive() == 0

demo/readdir.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# A Linux-only demo
23
#
34
import sys
@@ -10,7 +11,7 @@
1011

1112

1213
def walk(basefd, path):
13-
print '{', path
14+
print('{', path)
1415
dirfd = lib.openat(basefd, path, 0)
1516
if dirfd < 0:
1617
# error in openat()
@@ -25,11 +26,11 @@ def walk(basefd, path):
2526
if result[0] == ffi.NULL:
2627
break
2728
name = ffi.string(dirent.d_name)
28-
print '%3d %s' % (dirent.d_type, name)
29+
print('%3d %s' % (dirent.d_type, name))
2930
if dirent.d_type == 4 and name != '.' and name != '..':
3031
walk(dirfd, name)
3132
lib.closedir(dir)
32-
print '}'
33+
print('}')
3334

3435

3536
walk(-1, "/tmp")

demo/readdir2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# A Linux-only demo, using set_source() instead of hard-coding the exact layouts
23
#
34
import sys
@@ -10,7 +11,7 @@
1011

1112

1213
def walk(basefd, path):
13-
print '{', path
14+
print('{', path)
1415
dirfd = lib.openat(basefd, path, 0)
1516
if dirfd < 0:
1617
# error in openat()
@@ -25,11 +26,11 @@ def walk(basefd, path):
2526
if result[0] == ffi.NULL:
2627
break
2728
name = ffi.string(dirent.d_name)
28-
print '%3d %s' % (dirent.d_type, name)
29+
print('%3d %s' % (dirent.d_type, name))
2930
if dirent.d_type == lib.DT_DIR and name != '.' and name != '..':
3031
walk(dirfd, name)
3132
lib.closedir(dir)
32-
print '}'
33+
print('}')
3334

3435

3536
walk(-1, "/tmp")

demo/readdir_ctypes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# A Linux-only demo
23
#
34
# For comparison purposes, this is a ctypes version of readdir.py.
@@ -44,7 +45,7 @@ class DIRENT(ctypes.Structure):
4445

4546

4647
def walk(basefd, path):
47-
print '{', path
48+
print('{', path)
4849
dirfd = openat(basefd, path, 0)
4950
if dirfd < 0:
5051
# error in openat()
@@ -59,11 +60,11 @@ def walk(basefd, path):
5960
if not result:
6061
break
6162
name = dirent.d_name
62-
print '%3d %s' % (dirent.d_type, name)
63+
print('%3d %s' % (dirent.d_type, name))
6364
if dirent.d_type == 4 and name != '.' and name != '..':
6465
walk(dirfd, name)
6566
closedir(dir)
66-
print '}'
67+
print('}')
6768

6869

6970
walk(-1, "/tmp")

demo/winclipboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
__author__ = "Israel Fruchter <[email protected]>"
23

34
import sys, os
@@ -8,7 +9,7 @@
89
try:
910
from _winclipboard_cffi import ffi, lib
1011
except ImportError:
11-
print 'run winclipboard_build first, then make sure the shared object is on sys.path'
12+
print('run winclipboard_build first, then make sure the shared object is on sys.path')
1213
sys.exit(1)
1314

1415
# ffi "knows" about the declared variables and functions from the

0 commit comments

Comments
 (0)