Ok, that might not have been very helpful and doesn't exactly answers your question...
I am not sure how Spyder is doing it exactly, and I can't figure out an equivalent of a single call to a function that will replicate this behaviour from a script. It think the magic is happening in spyderlib/widgets/externalshell/monitor.py and/or namespacebrowser.py. Maybe that could be a feature request? Regards, David On 16 January 2014 21:45, David Verelst <[email protected]> wrote: > Hi, > > Do you mind sharing a little bit of information regarding your setup, such > as Spyder version and OS? That helps us to understand what is happening on > your end since Spyder has seen a lot of changes the last few months. > > The importing of Matlab variables is done in spyderlib/utils/iofuncs.py. > You can browse through the current version > here<https://bitbucket.org/spyder-ide/spyderlib/src/2d6ef53e0cfcda5c79721ac4de3a6500c5f28c50/spyderlib/utils/iofuncs.py?at=default>, > or look at the version from Stevens branch > here<https://bitbucket.org/blink1073/spyderlib/src/d90a3f72e4f6798454fb3b7235d5533206186744/spyderlib/utils/iofuncs.py?at=variable-explorer-drag-n-drop>(there > is pull request on that > here<https://bitbucket.org/spyder-ide/spyderlib/pull-request/4/improved-drag-and-drop-behavior-in-editor/diff>). > The latter holds certain improvements that have not yet been merged with > the main Spyder development branch. > > A small example (taken from iofuncs.py from Stevens branch) on how you > could import Matlab variables using a script: > > from spyderlib.utils.iofuncs import get_matlab_valueimport scipy.io as spio > > out = spio.loadmat(filename)for key, value in list(out.items()): > out[key] = get_matlab_value(value)# now you can access the variable(s) > you saved in the matlab file as follows > matlab_var = out['matlab_var_name']# all matlab variables are nested under > matlab_var and are accessible as a dictionaries > > Unfortunately there isn't yet an easy one-stop function to import a Matlab > .mat file with exactly the same behaviour as in Matlab. As it currently > stands now, a users is required to "browse" a bit through the output of > spio.loadmat, and that can be a bit cumbersome. The MatlabStruct class in > iofuncs.py from Steven improves the situation over the default > scipy.io.loadmat behaviour. > > Regards, > David > > > On 16 January 2014 13:48, egayer <[email protected]> wrote: > >> Hi, >> >> I am wondering how spider manages to import .mat file directly into the >> variable explorer (by double clicking on the .mat file) while the content >> of a .mat file is nested when using scipy.io.loadmat >> >> for example to load a mat file 'dummy.mat' that contains 2 matrix A and B >> : >> >> 1) I double click on the file from the spider file explorer and A and B >> will be added in the variable explorer >> >> 2) using scipy.io I do: >> >> x=scipy.io.loadmat('dummy.mat') >> >> and A and B are nested into x >> >> thanks for your help >> Eric >> >> -- >> You received this message because you are subscribed to the Google Groups >> "spyder" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/spyderlib. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- You received this message because you are subscribed to the Google Groups "spyder" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/spyderlib. For more options, visit https://groups.google.com/groups/opt_out.
