Error using idlsave in IPython
![](https://secure.gravatar.com/avatar/baf74ca1640047f08e0c998159d01fc5.jpg?s=120&d=mm&r=g)
Hello, Could you help me to clarify the following idlsave data accessing issue? Quick update: This seems to be an issue with IPython. s1['dn'] call works fine within regular python shell. I1 from scipy import io I2 s1 = io.idl.readsav('test.sav') I3 s1? Type: AttrDict Base Class: <class 'scipy.io.idl.AttrDict'> String Form: {'dn': array([ 1.02282184e+07, 1.05383408e+07, 1.08758739e+07, 1.12449965e+07, 1. <...> (('r', 'R'), '>f8'), (('v', 'V'), '>f8')]), 'tfit': array([ 4.82394886e+02, 4.18176107e-01])} Namespace: Interactive Length: 11 File: /usr/lib64/python2.7/site-packages/scipy/io/idl.py Definition: s1(self, name) ### Why is the following call failing? ### I4 s1['dn'] --------------------------------------------------------------------------- KeyError Traceback (most recent call last) /home/gsever/Desktop/python-repo/ipython/IPython/core/prefilter.pyc in prefilter_lines(self, lines, continue_prompt) 358 for lnum, line in enumerate(llines) ]) 359 else: --> 360 out = self.prefilter_line(llines[0], continue_prompt) 361 362 return out /home/gsever/Desktop/python-repo/ipython/IPython/core/prefilter.pyc in prefilter_line(self, line, continue_prompt) 333 return normal_handler.handle(line_info) 334 --> 335 prefiltered = self.prefilter_line_info(line_info) 336 # print "prefiltered line: %r" % prefiltered 337 return prefiltered /home/gsever/Desktop/python-repo/ipython/IPython/core/prefilter.pyc in prefilter_line_info(self, line_info) 273 # print "prefilter_line_info: ", line_info 274 handler = self.find_handler(line_info) --> 275 return handler.handle(line_info) 276 277 def find_handler(self, line_info): /home/gsever/Desktop/python-repo/ipython/IPython/core/prefilter.pyc in handle(self, line_info) 813 814 force_auto = isinstance(obj, IPyAutocall) --> 815 auto_rewrite = getattr(obj, 'rewrite', True) 816 817 if esc == ESC_QUOTE: /usr/lib64/python2.7/site-packages/scipy/io/idl.pyc in __getitem__(self, name) 657 658 def __getitem__(self, name): --> 659 return super(AttrDict, self).__getitem__(name.lower()) 660 661 def __setitem__(self, key, value): KeyError: 'rewrite' Back then I was accessing this key via (when idlsave was a separate module): s1.variables['dn'] but it is long gone in the scipy. The following works. Is this the correct way to access variables from this dictionary? I14 s1.get('dn') O14 array([ 1.02282184e+07, 1.05383408e+07, 1.08758739e+07, 1.12449965e+07, 1.16508267e+07, 1.20997100e+07, Thanks. -- Gökhan
![](https://secure.gravatar.com/avatar/7f1ae3f14fd5b87c2c3f7b36014e185c.jpg?s=120&d=mm&r=g)
On 10 November 2011 15:33, Gökhan Sever <gokhansever@gmail.com> wrote:
Hello,
Could you help me to clarify the following idlsave data accessing issue? Quick update: This seems to be an issue with IPython. s1['dn'] call works fine within regular python shell.
The AttrDict object tries to do item lookup from attribute access, but if the name is not found, it doesn't translate the error to an AttributeError. IPython looks for a particular attribute to control its input filtering behaviour, but it's not prepared for getattr() to raise a KeyError. IPython should probably catch arbitrary errors there. Feel free to file an issue so we don't forget about it: https://github.com/ipython/ipython/issues Thomas
![](https://secure.gravatar.com/avatar/baf74ca1640047f08e0c998159d01fc5.jpg?s=120&d=mm&r=g)
On Thu, Nov 10, 2011 at 9:09 AM, Thomas Kluyver <takowl@gmail.com> wrote:
On 10 November 2011 15:33, Gökhan Sever <gokhansever@gmail.com> wrote:
Hello,
Could you help me to clarify the following idlsave data accessing issue? Quick update: This seems to be an issue with IPython. s1['dn'] call works fine within regular python shell.
The AttrDict object tries to do item lookup from attribute access, but if the name is not found, it doesn't translate the error to an AttributeError. IPython looks for a particular attribute to control its input filtering behaviour, but it's not prepared for getattr() to raise a KeyError. IPython should probably catch arbitrary errors there. Feel free to file an issue so we don't forget about it:
https://github.com/ipython/ipython/issues
Thomas
Thanks Thomas, created https://github.com/ipython/ipython/issues/988 -- Gökhan
participants (2)
-
Gökhan Sever
-
Thomas Kluyver