From c870360cc5e0b06054ab92a649f034f47824bf3b 2010-01-06 00:36:42 From: Fernando Perez Date: 2010-01-06 00:36:42 Subject: [PATCH] Simpler/cleaner version of %who_ls. Functionally equivalent but with simpler and faster code (I was fixing up pylab support and saw this old code, fixed it up to more modern standards). --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 879047d..f95d3dc 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -875,7 +875,7 @@ Currently the magic system has the following functions:\n""" show_all=opt('a'),ignore_case=ignore_case) except: shell.showtraceback() - + def magic_who_ls(self, parameter_s=''): """Return a sorted list of all interactive variables. @@ -885,17 +885,15 @@ Currently the magic system has the following functions:\n""" user_ns = self.shell.user_ns internal_ns = self.shell.internal_ns user_config_ns = self.shell.user_config_ns - out = [] + out = [ i for i in user_ns + if not i.startswith('_') \ + and not (i in internal_ns or i in user_config_ns) ] + typelist = parameter_s.split() + if typelist: + typeset = set(typelist) + out = [i for i in out if type(i).__name__ in typeset] - for i in user_ns: - if not (i.startswith('_') or i.startswith('_i')) \ - and not (i in internal_ns or i in user_config_ns): - if typelist: - if type(user_ns[i]).__name__ in typelist: - out.append(i) - else: - out.append(i) out.sort() return out