MCPcopy Create free account
hub / github.com/ipython/ipython / __call__

Method __call__

IPython/lib/demo.py:451–503  ·  view source on GitHub ↗

run a block of the demo. If index is given, it should be an integer >=1 and <= nblocks. This means that the calling convention is one off from typical Python lists. The reason for the inconsistency is that the demo always prints 'Block n/N, and N is the total, so i

(self,index=None)

Source from the content-addressed store, hash-verified

449 exec(source, self.user_ns)
450
451 def __call__(self,index=None):
452 """run a block of the demo.
453
454 If index is given, it should be an integer >=1 and <= nblocks. This
455 means that the calling convention is one off from typical Python
456 lists. The reason for the inconsistency is that the demo always
457 prints &#x27;Block n/N, and N is the total, so it would be very odd to use
458 zero-indexing here."""
459
460 index = self._get_index(index)
461 if index is None:
462 return
463 try:
464 marquee = self.marquee
465 next_block = self.src_blocks[index]
466 self.block_index += 1
467 if self._silent[index]:
468 print(marquee('Executing silent block # %s (%s remaining)' %
469 (index,self.nblocks-index-1)))
470 else:
471 self.pre_cmd()
472 self.show(index)
473 if self.auto_all or self._auto[index]:
474 print(marquee('output:'))
475 else:
476 print(marquee('Press <q> to quit, <Enter> to execute...'), end=' ')
477 ans = py3compat.input().strip()
478 if ans:
479 print(marquee('Block NOT executed'))
480 return
481 try:
482 save_argv = sys.argv
483 sys.argv = self.sys_argv
484 self.run_cell(next_block)
485 self.post_cmd()
486 finally:
487 sys.argv = save_argv
488
489 except:
490 if self.inside_ipython:
491 self.ip_showtb(filename=self.fname)
492 else:
493 if self.inside_ipython:
494 self.ip_ns.update(self.user_ns)
495
496 if self.block_index == self.nblocks:
497 mq1 = self.marquee('END OF DEMO')
498 if mq1:
499 # avoid spurious print if empty marquees are used
500 print()
501 print(mq1)
502 print(self.marquee('Use <demo_name>.reset() if you want to rerun it.'))
503 self.finished = True
504
505 # These methods are meant to be overridden by subclasses who may wish to
506 # customize the behavior of of their demos.

Callers

nothing calls this directly

Calls 8

_get_indexMethod · 0.95
pre_cmdMethod · 0.95
showMethod · 0.95
run_cellMethod · 0.95
post_cmdMethod · 0.95
marqueeMethod · 0.95
marqueeFunction · 0.90
updateMethod · 0.45

Tested by

no test coverage detected