[IPython-User] Error using idlsave in IPython

Gökhan Sever gokhansever@gmail....
Thu Nov 10 09:33:22 CST 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20111110/768972c1/attachment.html 


More information about the IPython-User mailing list