diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-03-24 12:51:19 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-03-24 12:51:19 -0400 |
| commit | ae03c59de609878e068920380667c5fd45f26650 (patch) | |
| tree | b8d2030f91f7f402c7db81ea8a8b53bbfc7107c1 /docs/features | |
| parent | f1aea756efc2f73755e172a82a79c752e9972c69 (diff) | |
| download | cmd2-git-ae03c59de609878e068920380667c5fd45f26650.tar.gz | |
ipy command now includes all of self.py_locals in the IPython environment
Diffstat (limited to 'docs/features')
| -rw-r--r-- | docs/features/embedded_python_shells.rst | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/docs/features/embedded_python_shells.rst b/docs/features/embedded_python_shells.rst index 8ff65ffe..71fb8197 100644 --- a/docs/features/embedded_python_shells.rst +++ b/docs/features/embedded_python_shells.rst @@ -8,19 +8,16 @@ arguments, it enters an interactive Python session. The session can call your ``cmd2`` application while maintaining isolation. You may optionally enable full access to to your application by setting -``self_in_py`` to ``True``. Enabling this flag adds ``self`` to the python -session, which is a reference to your ``cmd2`` application. This can be useful -for debugging your application. +``self.self_in_py`` to ``True``. Enabling this flag adds ``self`` to the +python session, which is a reference to your ``cmd2`` application. This can be +useful for debugging your application. + +Anything in ``self.py_locals`` is always available in the Python environment. The ``app`` object (or your custom name) provides access to application commands through raw commands. For example, any application command call be called with ``app("<command>")``. -:: - - >>> app('say --piglatin Blah') - lahBay - More Python examples: :: @@ -114,12 +111,13 @@ be present:: The ``ipy`` command enters an interactive IPython_ session. Similar to an interactive Python session, this shell can access your application instance via -``self`` and any changes to your application made via ``self`` will persist. -However, any local or global variable created within the ``ipy`` shell will not -persist. Within the ``ipy`` shell, you cannot call "back" to your application -with ``cmd("")``, however you can run commands directly like so:: +``self`` if ``self.self_in_py`` is ``True`` and any changes to your application +made via ``self`` will persist. However, any local or global variable created +within the ``ipy`` shell will not persist. - self.onecmd_plus_hooks('help') +Also, as in the interactive Python session, the ``ipy`` shell has access to the +contents of ``self.py_locals`` and can call back into the application using the +``app`` object (or your custom name). IPython_ provides many advantages, including: |
