Return a sorted list of all interactive variables. If arguments are given, only variables of types matching these arguments are returned. Examples -------- Define two variables and list them with who_ls:: In [1]: alpha = 123 In [2]: be
(self, parameter_s='')
| 245 | @skip_doctest |
| 246 | @line_magic |
| 247 | def who_ls(self, parameter_s=''): |
| 248 | """Return a sorted list of all interactive variables. |
| 249 | |
| 250 | If arguments are given, only variables of types matching these |
| 251 | arguments are returned. |
| 252 | |
| 253 | Examples |
| 254 | -------- |
| 255 | |
| 256 | Define two variables and list them with who_ls:: |
| 257 | |
| 258 | In [1]: alpha = 123 |
| 259 | |
| 260 | In [2]: beta = 'test' |
| 261 | |
| 262 | In [3]: %who_ls |
| 263 | Out[3]: ['alpha', 'beta'] |
| 264 | |
| 265 | In [4]: %who_ls int |
| 266 | Out[4]: ['alpha'] |
| 267 | |
| 268 | In [5]: %who_ls str |
| 269 | Out[5]: ['beta'] |
| 270 | """ |
| 271 | |
| 272 | user_ns = self.shell.user_ns |
| 273 | user_ns_hidden = self.shell.user_ns_hidden |
| 274 | nonmatching = object() # This can never be in user_ns |
| 275 | out = [ i for i in user_ns |
| 276 | if not i.startswith('_') \ |
| 277 | and (user_ns[i] is not user_ns_hidden.get(i, nonmatching)) ] |
| 278 | |
| 279 | typelist = parameter_s.split() |
| 280 | if typelist: |
| 281 | typeset = set(typelist) |
| 282 | out = [i for i in out if type(user_ns[i]).__name__ in typeset] |
| 283 | |
| 284 | out.sort() |
| 285 | return out |
| 286 | |
| 287 | @skip_doctest |
| 288 | @line_magic |
no test coverage detected