[SciPy-dev] change print statements to print functions in docstrings

Matthew Brett matthew.brett at gmail.com
Mon Aug 17 14:26:21 EDT 2009


On Mon, Aug 17, 2009 at 7:26 AM, Gael
Varoquaux<gael.varoquaux at normalesup.org> wrote:
> On Mon, Aug 17, 2009 at 08:36:07AM -0400, Alan G Isaac wrote:
>> On 8/17/2009 2:46 AM Gael Varoquaux apparently wrote:
>> > OK, I am confused by the fact that __builtins__ as a print function that
>> > matches the Python 3.x print function. You can see this doing
>> > '$ pydoc __builtin__.print' and I believe this is what is confusing
>> > IPython too. What you are saying is that that function does not kick in
>> > if we don't do the __future__ import, right?

It does seem that IPython autocall is detecting print as being a
callable, in python 2.6, but it's not because of the from __future__
import I don't think

In [1]: type(print) # print is a statement -> error
------------------------------------------------------------
   File "<ipython console>", line 1
     type(print) # print is a statement -> error
              ^
SyntaxError: invalid syntax


In [2]: print 1,2
------> print(1,2)
(1, 2)

In [3]: autocall 0
Automatic calling is: OFF

In [4]: print 1, 2
1 2

In [5]: from __future__ import print_function

In [6]: type(print)
Out[6]: <type 'builtin_function_or_method'>

In [7]: print 1, 2
------------------------------------------------------------
   File "<ipython console>", line 1
     print 1, 2 # of course it's an error
           ^
SyntaxError: invalid syntax


In [8]: print(1, 2)
1 2

See you,

Matthew



More information about the SciPy-Dev mailing list