Permalink
Browse files

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).
  • Loading branch information...
1 parent 48d63c6 commit c870360cc5e0b06054ab92a649f034f47824bf3b @fperez fperez committed Jan 6, 2010
Showing with 8 additions and 10 deletions.
  1. +8 −10 IPython/core/magic.py
View
@@ -875,7 +875,7 @@ def magic_psearch(self, parameter_s=''):
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 @@ def magic_who_ls(self, parameter_s=''):
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

0 comments on commit c870360

Please sign in to comment.