Cython has moved to github.
cython-devel
view tests/run/print_function.pyx @ 3068:f9baa86d0372
support 'from __future__ import print_function' in Py2.6+
| author | Stefan Behnel <scoder@users.berlios.de> |
|---|---|
| date | Wed Mar 10 08:46:58 2010 +0100 (2 years ago) |
| parents | tests/run/print.pyx@401e253547d0 |
| children |
line source
2 # Py2.6 and later only!
3 from __future__ import print_function
5 def print_to_stdout(a, b):
6 """
7 >>> print_to_stdout(1, 'test')
8 <BLANKLINE>
9 1
10 1 test
11 1 test
12 1 test 42 spam
13 """
14 print()
15 print(a)
16 print(a, end=' ')
17 print(b)
18 print(a, b)
19 print(a, b, end=' ')
20 print(42, u"spam")
22 def print_assign(a, b):
23 """
24 >>> print_assign(1, 'test')
25 <BLANKLINE>
26 1
27 1 test
28 1 test
29 1 test 42 spam
30 """
31 x = print
32 x()
33 x(a)
34 x(a, end=' ')
35 x(b)
36 x(a, b)
37 x(a, b, end=' ')
38 x(42, u"spam")
41 try:
42 from StringIO import StringIO
43 except ImportError:
44 from io import StringIO
46 def print_to_stringio(stream, a, b):
47 """
48 >>> stream = StringIO()
49 >>> print_to_stringio(stream, 1, 'test')
50 >>> print(stream.getvalue())
51 <BLANKLINE>
52 1
53 1 test
54 1 test
55 1 test 42 spam
56 <BLANKLINE>
57 """
58 print(file=stream)
59 print(a, file=stream)
60 print(a, end=' ', file=stream)
61 print(b, file=stream)
62 print(a, b, file=stream)
63 print(a, b, end=' ', file=stream)
64 print(42, u"spam", file=stream)
