[IPython-user] More ipython and python2.5: 'with' statements

Fernando Perez Fernando.Perez at colorado.edu
Fri Mar 10 00:01:25 CST 2006


Zachary Pincus wrote:
> Hi folks,
> 
> In python 2.6, 'with' and 'as' will become keywords (see http:// 
> www.python.org/doc/peps/pep-0343/ ). Python 2.5 gives a warning about  
> these symbols if used, and 'with blocks' can be used with a 'from  
> __future__ import with_statement' line.
> 
> However, ipython seems to somehow cause 'with' and 'as' to be treated  
> as reserved keywords even if no 'from __future__' line is executed.  
> (See below for example.)
> 
> I'm not sure how this is happening. Any thoughts?

well, ipython certainly isn't doing a direct import:

maqroll[ipython]> egrep -r with_statement *
maqroll[ipython]>

but you have to keep in mind that ipython imports a ton of modules from the 
standard library.  I wonder if, in 2.5, any of the stdlib modules have these 
future imports, which would explain the behavior you are seeing.

You can see what modules are loaded at startup with:

  >>> import sys
 >>> sys.modules.keys()
['copy_reg', '__main__', 'site', '__builtin__', 'atexit', 'encodings', 
'posixpath', 'encodings.codecs', 'os.path', '_codecs', 'encodings.exceptions', 
'stat', 'zipimport', 'warnings', 'encodings.types', 'UserDict', 
'encodings.utf_8', 'sys', 'codecs', 'readline', 'types', 'rlcompleter', 
'signal', 'linecache', 'posix', 'encodings.aliases', 'exceptions', 'os']

In ipython, the same list is a LOT longer.  If I understand things correctly, 
all it takes is one of these to pull the with/as import for you to see the 
behavior mentioned in your message.

That's the best I can come up with right now, I'm afraid.

Regards,

f




More information about the IPython-user mailing list