Demo-Mode in IPython broken?

Albert Brandl albert at brasco.at
Sun Jul 29 12:22:51 EDT 2018


Hi!

The IPython documentation mentions a demo mode that can be used
to execute chunks of a Python file that are separated by special
comments (e.g. "# <demo> stop").

The annotated Python file can be executed by importing `Demo` from
`IPython.lib.demo`, instantiating it using the file name and calling
the `Demo` instance:

from IPython.lib.demo import Demo
d = Demo("some_file.py")
d()

According to the documentation, all names that are defined in such a
chunk are transferred to the global IPython namespace. This would
allow me to interactively inspect the names etc.

It looks like this feature does not work in the version 6.4.0 of
IPython: the global namespace does not change after executing any chunk
of a Python file. The Demo instance has a dictionary called `user_ns`
that _is_ updated when a chunk is executed, but using it to access the
names is quite clumsy ;-).

Is this a known bug? Do you have a suggestion how I could emulate the
behavior of the demo mode by other means (not necessarily with IPython)?

TIA and best regards,

Albert



More information about the Python-list mailing list