##// END OF EJS Templates
Merge pull request #13790 from jcollins1983/typo_fix...
Matthias Bussonnier -
r27824:5577a476 merge
parent child Browse files
Show More
@@ -1,711 +1,711 b''
1 1 """Implementation of namespace-related magic functions.
2 2 """
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (c) 2012 The IPython Development Team.
5 5 #
6 6 # Distributed under the terms of the Modified BSD License.
7 7 #
8 8 # The full license is in the file COPYING.txt, distributed with this software.
9 9 #-----------------------------------------------------------------------------
10 10
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14 14
15 15 # Stdlib
16 16 import gc
17 17 import re
18 18 import sys
19 19
20 20 # Our own packages
21 21 from IPython.core import page
22 22 from IPython.core.error import StdinNotImplementedError, UsageError
23 23 from IPython.core.magic import Magics, magics_class, line_magic
24 24 from IPython.testing.skipdoctest import skip_doctest
25 25 from IPython.utils.encoding import DEFAULT_ENCODING
26 26 from IPython.utils.openpy import read_py_file
27 27 from IPython.utils.path import get_py_filename
28 28
29 29 #-----------------------------------------------------------------------------
30 30 # Magic implementation classes
31 31 #-----------------------------------------------------------------------------
32 32
33 33 @magics_class
34 34 class NamespaceMagics(Magics):
35 35 """Magics to manage various aspects of the user's namespace.
36 36
37 37 These include listing variables, introspecting into them, etc.
38 38 """
39 39
40 40 @line_magic
41 41 def pinfo(self, parameter_s='', namespaces=None):
42 42 """Provide detailed information about an object.
43 43
44 44 '%pinfo object' is just a synonym for object? or ?object."""
45 45
46 46 #print 'pinfo par: <%s>' % parameter_s # dbg
47 47 # detail_level: 0 -> obj? , 1 -> obj??
48 48 detail_level = 0
49 49 # We need to detect if we got called as 'pinfo pinfo foo', which can
50 50 # happen if the user types 'pinfo foo?' at the cmd line.
51 51 pinfo,qmark1,oname,qmark2 = \
52 52 re.match(r'(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
53 53 if pinfo or qmark1 or qmark2:
54 54 detail_level = 1
55 55 if "*" in oname:
56 56 self.psearch(oname)
57 57 else:
58 58 self.shell._inspect('pinfo', oname, detail_level=detail_level,
59 59 namespaces=namespaces)
60 60
61 61 @line_magic
62 62 def pinfo2(self, parameter_s='', namespaces=None):
63 63 """Provide extra detailed information about an object.
64 64
65 65 '%pinfo2 object' is just a synonym for object?? or ??object."""
66 66 self.shell._inspect('pinfo', parameter_s, detail_level=1,
67 67 namespaces=namespaces)
68 68
69 69 @skip_doctest
70 70 @line_magic
71 71 def pdef(self, parameter_s='', namespaces=None):
72 72 """Print the call signature for any callable object.
73 73
74 74 If the object is a class, print the constructor information.
75 75
76 76 Examples
77 77 --------
78 78 ::
79 79
80 80 In [3]: %pdef urllib.urlopen
81 81 urllib.urlopen(url, data=None, proxies=None)
82 82 """
83 83 self.shell._inspect('pdef',parameter_s, namespaces)
84 84
85 85 @line_magic
86 86 def pdoc(self, parameter_s='', namespaces=None):
87 87 """Print the docstring for an object.
88 88
89 89 If the given object is a class, it will print both the class and the
90 90 constructor docstrings."""
91 91 self.shell._inspect('pdoc',parameter_s, namespaces)
92 92
93 93 @line_magic
94 94 def psource(self, parameter_s='', namespaces=None):
95 95 """Print (or run through pager) the source code for an object."""
96 96 if not parameter_s:
97 97 raise UsageError('Missing object name.')
98 98 self.shell._inspect('psource',parameter_s, namespaces)
99 99
100 100 @line_magic
101 101 def pfile(self, parameter_s='', namespaces=None):
102 102 """Print (or run through pager) the file where an object is defined.
103 103
104 104 The file opens at the line where the object definition begins. IPython
105 105 will honor the environment variable PAGER if set, and otherwise will
106 106 do its best to print the file in a convenient form.
107 107
108 108 If the given argument is not an object currently defined, IPython will
109 109 try to interpret it as a filename (automatically adding a .py extension
110 110 if needed). You can thus use %pfile as a syntax highlighting code
111 111 viewer."""
112 112
113 113 # first interpret argument as an object name
114 114 out = self.shell._inspect('pfile',parameter_s, namespaces)
115 115 # if not, try the input as a filename
116 116 if out == 'not found':
117 117 try:
118 118 filename = get_py_filename(parameter_s)
119 119 except IOError as msg:
120 120 print(msg)
121 121 return
122 122 page.page(self.shell.pycolorize(read_py_file(filename, skip_encoding_cookie=False)))
123 123
124 124 @line_magic
125 125 def psearch(self, parameter_s=''):
126 126 """Search for object in namespaces by wildcard.
127 127
128 128 %psearch [options] PATTERN [OBJECT TYPE]
129 129
130 130 Note: ? can be used as a synonym for %psearch, at the beginning or at
131 131 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
132 132 rest of the command line must be unchanged (options come first), so
133 133 for example the following forms are equivalent
134 134
135 135 %psearch -i a* function
136 136 -i a* function?
137 137 ?-i a* function
138 138
139 139 Arguments:
140 140
141 141 PATTERN
142 142
143 143 where PATTERN is a string containing * as a wildcard similar to its
144 144 use in a shell. The pattern is matched in all namespaces on the
145 145 search path. By default objects starting with a single _ are not
146 146 matched, many IPython generated objects have a single
147 147 underscore. The default is case insensitive matching. Matching is
148 148 also done on the attributes of objects and not only on the objects
149 149 in a module.
150 150
151 151 [OBJECT TYPE]
152 152
153 153 Is the name of a python type from the types module. The name is
154 154 given in lowercase without the ending type, ex. StringType is
155 155 written string. By adding a type here only objects matching the
156 156 given type are matched. Using all here makes the pattern match all
157 157 types (this is the default).
158 158
159 159 Options:
160 160
161 161 -a: makes the pattern match even objects whose names start with a
162 162 single underscore. These names are normally omitted from the
163 163 search.
164 164
165 165 -i/-c: make the pattern case insensitive/sensitive. If neither of
166 166 these options are given, the default is read from your configuration
167 167 file, with the option ``InteractiveShell.wildcards_case_sensitive``.
168 168 If this option is not specified in your configuration file, IPython's
169 169 internal default is to do a case sensitive search.
170 170
171 171 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
172 172 specify can be searched in any of the following namespaces:
173 173 'builtin', 'user', 'user_global','internal', 'alias', where
174 174 'builtin' and 'user' are the search defaults. Note that you should
175 175 not use quotes when specifying namespaces.
176 176
177 177 -l: List all available object types for object matching. This function
178 178 can be used without arguments.
179 179
180 180 'Builtin' contains the python module builtin, 'user' contains all
181 181 user data, 'alias' only contain the shell aliases and no python
182 182 objects, 'internal' contains objects used by IPython. The
183 183 'user_global' namespace is only used by embedded IPython instances,
184 184 and it contains module-level globals. You can add namespaces to the
185 185 search with -s or exclude them with -e (these options can be given
186 186 more than once).
187 187
188 188 Examples
189 189 --------
190 190 ::
191 191
192 192 %psearch a* -> objects beginning with an a
193 193 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
194 194 %psearch a* function -> all functions beginning with an a
195 195 %psearch re.e* -> objects beginning with an e in module re
196 196 %psearch r*.e* -> objects that start with e in modules starting in r
197 197 %psearch r*.* string -> all strings in modules beginning with r
198 198
199 199 Case sensitive search::
200 200
201 201 %psearch -c a* list all object beginning with lower case a
202 202
203 203 Show objects beginning with a single _::
204 204
205 205 %psearch -a _* list objects beginning with a single underscore
206 206
207 207 List available objects::
208 208
209 209 %psearch -l list all available object types
210 210 """
211 211 # default namespaces to be searched
212 212 def_search = ['user_local', 'user_global', 'builtin']
213 213
214 214 # Process options/args
215 215 opts,args = self.parse_options(parameter_s,'cias:e:l',list_all=True)
216 216 opt = opts.get
217 217 shell = self.shell
218 218 psearch = shell.inspector.psearch
219 219
220 220 # select list object types
221 221 list_types = False
222 222 if 'l' in opts:
223 223 list_types = True
224 224
225 225 # select case options
226 226 if 'i' in opts:
227 227 ignore_case = True
228 228 elif 'c' in opts:
229 229 ignore_case = False
230 230 else:
231 231 ignore_case = not shell.wildcards_case_sensitive
232 232
233 233 # Build list of namespaces to search from user options
234 234 def_search.extend(opt('s',[]))
235 235 ns_exclude = ns_exclude=opt('e',[])
236 236 ns_search = [nm for nm in def_search if nm not in ns_exclude]
237 237
238 238 # Call the actual search
239 239 try:
240 240 psearch(args,shell.ns_table,ns_search,
241 241 show_all=opt('a'),ignore_case=ignore_case, list_types=list_types)
242 242 except:
243 243 shell.showtraceback()
244 244
245 245 @skip_doctest
246 246 @line_magic
247 247 def who_ls(self, parameter_s=''):
248 248 """Return a sorted list of all interactive variables.
249 249
250 250 If arguments are given, only variables of types matching these
251 251 arguments are returned.
252 252
253 253 Examples
254 254 --------
255 255 Define two variables and list them with who_ls::
256 256
257 257 In [1]: alpha = 123
258 258
259 259 In [2]: beta = 'test'
260 260
261 261 In [3]: %who_ls
262 262 Out[3]: ['alpha', 'beta']
263 263
264 264 In [4]: %who_ls int
265 265 Out[4]: ['alpha']
266 266
267 267 In [5]: %who_ls str
268 268 Out[5]: ['beta']
269 269 """
270 270
271 271 user_ns = self.shell.user_ns
272 272 user_ns_hidden = self.shell.user_ns_hidden
273 273 nonmatching = object() # This can never be in user_ns
274 274 out = [ i for i in user_ns
275 275 if not i.startswith('_') \
276 276 and (user_ns[i] is not user_ns_hidden.get(i, nonmatching)) ]
277 277
278 278 typelist = parameter_s.split()
279 279 if typelist:
280 280 typeset = set(typelist)
281 281 out = [i for i in out if type(user_ns[i]).__name__ in typeset]
282 282
283 283 out.sort()
284 284 return out
285 285
286 286 @skip_doctest
287 287 @line_magic
288 288 def who(self, parameter_s=''):
289 289 """Print all interactive variables, with some minimal formatting.
290 290
291 291 If any arguments are given, only variables whose type matches one of
292 292 these are printed. For example::
293 293
294 294 %who function str
295 295
296 296 will only list functions and strings, excluding all other types of
297 297 variables. To find the proper type names, simply use type(var) at a
298 298 command line to see how python prints type names. For example:
299 299
300 300 ::
301 301
302 302 In [1]: type('hello')\\
303 303 Out[1]: <type 'str'>
304 304
305 305 indicates that the type name for strings is 'str'.
306 306
307 307 ``%who`` always excludes executed names loaded through your configuration
308 308 file and things which are internal to IPython.
309 309
310 310 This is deliberate, as typically you may load many modules and the
311 311 purpose of %who is to show you only what you've manually defined.
312 312
313 313 Examples
314 314 --------
315 315
316 316 Define two variables and list them with who::
317 317
318 318 In [1]: alpha = 123
319 319
320 320 In [2]: beta = 'test'
321 321
322 322 In [3]: %who
323 323 alpha beta
324 324
325 325 In [4]: %who int
326 326 alpha
327 327
328 328 In [5]: %who str
329 329 beta
330 330 """
331 331
332 332 varlist = self.who_ls(parameter_s)
333 333 if not varlist:
334 334 if parameter_s:
335 335 print('No variables match your requested type.')
336 336 else:
337 337 print('Interactive namespace is empty.')
338 338 return
339 339
340 340 # if we have variables, move on...
341 341 count = 0
342 342 for i in varlist:
343 343 print(i+'\t', end=' ')
344 344 count += 1
345 345 if count > 8:
346 346 count = 0
347 347 print()
348 348 print()
349 349
350 350 @skip_doctest
351 351 @line_magic
352 352 def whos(self, parameter_s=''):
353 353 """Like %who, but gives some extra information about each variable.
354 354
355 355 The same type filtering of %who can be applied here.
356 356
357 357 For all variables, the type is printed. Additionally it prints:
358 358
359 359 - For {},[],(): their length.
360 360
361 361 - For numpy arrays, a summary with shape, number of
362 362 elements, typecode and size in memory.
363 363
364 364 - Everything else: a string representation, snipping their middle if
365 365 too long.
366 366
367 367 Examples
368 368 --------
369 369 Define two variables and list them with whos::
370 370
371 371 In [1]: alpha = 123
372 372
373 373 In [2]: beta = 'test'
374 374
375 375 In [3]: %whos
376 376 Variable Type Data/Info
377 377 --------------------------------
378 378 alpha int 123
379 379 beta str test
380 380 """
381 381
382 382 varnames = self.who_ls(parameter_s)
383 383 if not varnames:
384 384 if parameter_s:
385 385 print('No variables match your requested type.')
386 386 else:
387 387 print('Interactive namespace is empty.')
388 388 return
389 389
390 390 # if we have variables, move on...
391 391
392 392 # for these types, show len() instead of data:
393 393 seq_types = ['dict', 'list', 'tuple']
394 394
395 395 # for numpy arrays, display summary info
396 396 ndarray_type = None
397 397 if 'numpy' in sys.modules:
398 398 try:
399 399 from numpy import ndarray
400 400 except ImportError:
401 401 pass
402 402 else:
403 403 ndarray_type = ndarray.__name__
404 404
405 405 # Find all variable names and types so we can figure out column sizes
406 406
407 407 # some types are well known and can be shorter
408 408 abbrevs = {'IPython.core.macro.Macro' : 'Macro'}
409 409 def type_name(v):
410 410 tn = type(v).__name__
411 411 return abbrevs.get(tn,tn)
412 412
413 413 varlist = [self.shell.user_ns[n] for n in varnames]
414 414
415 415 typelist = []
416 416 for vv in varlist:
417 417 tt = type_name(vv)
418 418
419 419 if tt=='instance':
420 420 typelist.append( abbrevs.get(str(vv.__class__),
421 421 str(vv.__class__)))
422 422 else:
423 423 typelist.append(tt)
424 424
425 425 # column labels and # of spaces as separator
426 426 varlabel = 'Variable'
427 427 typelabel = 'Type'
428 428 datalabel = 'Data/Info'
429 429 colsep = 3
430 430 # variable format strings
431 431 vformat = "{0:<{varwidth}}{1:<{typewidth}}"
432 432 aformat = "%s: %s elems, type `%s`, %s bytes"
433 433 # find the size of the columns to format the output nicely
434 434 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
435 435 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
436 436 # table header
437 437 print(varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
438 438 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1))
439 439 # and the table itself
440 440 kb = 1024
441 441 Mb = 1048576 # kb**2
442 442 for vname,var,vtype in zip(varnames,varlist,typelist):
443 443 print(vformat.format(vname, vtype, varwidth=varwidth, typewidth=typewidth), end=' ')
444 444 if vtype in seq_types:
445 445 print("n="+str(len(var)))
446 446 elif vtype == ndarray_type:
447 447 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
448 448 if vtype==ndarray_type:
449 449 # numpy
450 450 vsize = var.size
451 451 vbytes = vsize*var.itemsize
452 452 vdtype = var.dtype
453 453
454 454 if vbytes < 100000:
455 455 print(aformat % (vshape, vsize, vdtype, vbytes))
456 456 else:
457 457 print(aformat % (vshape, vsize, vdtype, vbytes), end=' ')
458 458 if vbytes < Mb:
459 459 print('(%s kb)' % (vbytes/kb,))
460 460 else:
461 461 print('(%s Mb)' % (vbytes/Mb,))
462 462 else:
463 463 try:
464 464 vstr = str(var)
465 465 except UnicodeEncodeError:
466 466 vstr = var.encode(DEFAULT_ENCODING,
467 467 'backslashreplace')
468 468 except:
469 469 vstr = "<object with id %d (str() failed)>" % id(var)
470 470 vstr = vstr.replace('\n', '\\n')
471 471 if len(vstr) < 50:
472 472 print(vstr)
473 473 else:
474 474 print(vstr[:25] + "<...>" + vstr[-25:])
475 475
476 476 @line_magic
477 477 def reset(self, parameter_s=''):
478 478 """Resets the namespace by removing all names defined by the user, if
479 479 called without arguments, or by removing some types of objects, such
480 480 as everything currently in IPython's In[] and Out[] containers (see
481 481 the parameters for details).
482 482
483 483 Parameters
484 484 ----------
485 485 -f
486 486 force reset without asking for confirmation.
487 487 -s
488 488 'Soft' reset: Only clears your namespace, leaving history intact.
489 489 References to objects may be kept. By default (without this option),
490 490 we do a 'hard' reset, giving you a new session and removing all
491 491 references to objects from the current session.
492 492 --aggressive
493 493 Try to aggressively remove modules from sys.modules ; this
494 494 may allow you to reimport Python modules that have been updated and
495 pick up changes, but can have unattended consequences.
495 pick up changes, but can have unintended consequences.
496 496
497 497 in
498 498 reset input history
499 499 out
500 500 reset output history
501 501 dhist
502 502 reset directory history
503 503 array
504 504 reset only variables that are NumPy arrays
505 505
506 506 See Also
507 507 --------
508 508 reset_selective : invoked as ``%reset_selective``
509 509
510 510 Examples
511 511 --------
512 512 ::
513 513
514 514 In [6]: a = 1
515 515
516 516 In [7]: a
517 517 Out[7]: 1
518 518
519 519 In [8]: 'a' in get_ipython().user_ns
520 520 Out[8]: True
521 521
522 522 In [9]: %reset -f
523 523
524 524 In [1]: 'a' in get_ipython().user_ns
525 525 Out[1]: False
526 526
527 527 In [2]: %reset -f in
528 528 Flushing input history
529 529
530 530 In [3]: %reset -f dhist in
531 531 Flushing directory history
532 532 Flushing input history
533 533
534 534 Notes
535 535 -----
536 536 Calling this magic from clients that do not implement standard input,
537 537 such as the ipython notebook interface, will reset the namespace
538 538 without confirmation.
539 539 """
540 540 opts, args = self.parse_options(parameter_s, "sf", "aggressive", mode="list")
541 541 if "f" in opts:
542 542 ans = True
543 543 else:
544 544 try:
545 545 ans = self.shell.ask_yes_no(
546 546 "Once deleted, variables cannot be recovered. Proceed (y/[n])?",
547 547 default='n')
548 548 except StdinNotImplementedError:
549 549 ans = True
550 550 if not ans:
551 551 print('Nothing done.')
552 552 return
553 553
554 554 if 's' in opts: # Soft reset
555 555 user_ns = self.shell.user_ns
556 556 for i in self.who_ls():
557 557 del(user_ns[i])
558 558 elif len(args) == 0: # Hard reset
559 559 self.shell.reset(new_session=False, aggressive=("aggressive" in opts))
560 560
561 561 # reset in/out/dhist/array: previously extensinions/clearcmd.py
562 562 ip = self.shell
563 563 user_ns = self.shell.user_ns # local lookup, heavily used
564 564
565 565 for target in args:
566 566 target = target.lower() # make matches case insensitive
567 567 if target == 'out':
568 568 print("Flushing output cache (%d entries)" % len(user_ns['_oh']))
569 569 self.shell.displayhook.flush()
570 570
571 571 elif target == 'in':
572 572 print("Flushing input history")
573 573 pc = self.shell.displayhook.prompt_count + 1
574 574 for n in range(1, pc):
575 575 key = '_i'+repr(n)
576 576 user_ns.pop(key,None)
577 577 user_ns.update(dict(_i=u'',_ii=u'',_iii=u''))
578 578 hm = ip.history_manager
579 579 # don't delete these, as %save and %macro depending on the
580 580 # length of these lists to be preserved
581 581 hm.input_hist_parsed[:] = [''] * pc
582 582 hm.input_hist_raw[:] = [''] * pc
583 583 # hm has internal machinery for _i,_ii,_iii, clear it out
584 584 hm._i = hm._ii = hm._iii = hm._i00 = u''
585 585
586 586 elif target == 'array':
587 587 # Support cleaning up numpy arrays
588 588 try:
589 589 from numpy import ndarray
590 590 # This must be done with items and not iteritems because
591 591 # we're going to modify the dict in-place.
592 592 for x,val in list(user_ns.items()):
593 593 if isinstance(val,ndarray):
594 594 del user_ns[x]
595 595 except ImportError:
596 596 print("reset array only works if Numpy is available.")
597 597
598 598 elif target == 'dhist':
599 599 print("Flushing directory history")
600 600 del user_ns['_dh'][:]
601 601
602 602 else:
603 603 print("Don't know how to reset ", end=' ')
604 604 print(target + ", please run `%reset?` for details")
605 605
606 606 gc.collect()
607 607
608 608 @line_magic
609 609 def reset_selective(self, parameter_s=''):
610 610 """Resets the namespace by removing names defined by the user.
611 611
612 612 Input/Output history are left around in case you need them.
613 613
614 614 %reset_selective [-f] regex
615 615
616 616 No action is taken if regex is not included
617 617
618 618 Options
619 619 -f : force reset without asking for confirmation.
620 620
621 621 See Also
622 622 --------
623 623 reset : invoked as ``%reset``
624 624
625 625 Examples
626 626 --------
627 627 We first fully reset the namespace so your output looks identical to
628 628 this example for pedagogical reasons; in practice you do not need a
629 629 full reset::
630 630
631 631 In [1]: %reset -f
632 632
633 633 Now, with a clean namespace we can make a few variables and use
634 634 ``%reset_selective`` to only delete names that match our regexp::
635 635
636 636 In [2]: a=1; b=2; c=3; b1m=4; b2m=5; b3m=6; b4m=7; b2s=8
637 637
638 638 In [3]: who_ls
639 639 Out[3]: ['a', 'b', 'b1m', 'b2m', 'b2s', 'b3m', 'b4m', 'c']
640 640
641 641 In [4]: %reset_selective -f b[2-3]m
642 642
643 643 In [5]: who_ls
644 644 Out[5]: ['a', 'b', 'b1m', 'b2s', 'b4m', 'c']
645 645
646 646 In [6]: %reset_selective -f d
647 647
648 648 In [7]: who_ls
649 649 Out[7]: ['a', 'b', 'b1m', 'b2s', 'b4m', 'c']
650 650
651 651 In [8]: %reset_selective -f c
652 652
653 653 In [9]: who_ls
654 654 Out[9]: ['a', 'b', 'b1m', 'b2s', 'b4m']
655 655
656 656 In [10]: %reset_selective -f b
657 657
658 658 In [11]: who_ls
659 659 Out[11]: ['a']
660 660
661 661 Notes
662 662 -----
663 663 Calling this magic from clients that do not implement standard input,
664 664 such as the ipython notebook interface, will reset the namespace
665 665 without confirmation.
666 666 """
667 667
668 668 opts, regex = self.parse_options(parameter_s,'f')
669 669
670 670 if 'f' in opts:
671 671 ans = True
672 672 else:
673 673 try:
674 674 ans = self.shell.ask_yes_no(
675 675 "Once deleted, variables cannot be recovered. Proceed (y/[n])? ",
676 676 default='n')
677 677 except StdinNotImplementedError:
678 678 ans = True
679 679 if not ans:
680 680 print('Nothing done.')
681 681 return
682 682 user_ns = self.shell.user_ns
683 683 if not regex:
684 684 print('No regex pattern specified. Nothing done.')
685 685 return
686 686 else:
687 687 try:
688 688 m = re.compile(regex)
689 689 except TypeError as e:
690 690 raise TypeError('regex must be a string or compiled pattern') from e
691 691 for i in self.who_ls():
692 692 if m.search(i):
693 693 del(user_ns[i])
694 694
695 695 @line_magic
696 696 def xdel(self, parameter_s=''):
697 697 """Delete a variable, trying to clear it from anywhere that
698 698 IPython's machinery has references to it. By default, this uses
699 699 the identity of the named object in the user namespace to remove
700 700 references held under other names. The object is also removed
701 701 from the output history.
702 702
703 703 Options
704 704 -n : Delete the specified name from all namespaces, without
705 705 checking their identity.
706 706 """
707 707 opts, varname = self.parse_options(parameter_s,'n')
708 708 try:
709 709 self.shell.del_var(varname, ('n' in opts))
710 710 except (NameError, ValueError) as e:
711 711 print(type(e).__name__ +": "+ str(e))
General Comments 0
You need to be logged in to leave comments. Login now