summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-02-17 11:24:28 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-02-17 11:24:28 -0500
commit555db5d98fc122dc21d3bb239c079d68272cc0c3 (patch)
tree25f9041650716c5be91926da39af0b0ebaca853f /cmd2/cmd2.py
parentdb9c3a6d455e2bb19be7ae295c73a28751a7b481 (diff)
downloadcmd2-git-555db5d98fc122dc21d3bb239c079d68272cc0c3.tar.gz
Updated documentation and tests
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index c7a0fa6d..3b1fbb6f 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -3120,7 +3120,9 @@ class Cmd(cmd.Cmd):
self._in_py = True
py_code_to_run = ''
- # Locals for the Python environment we are creating
+ # Use self.py_locals as the locals() dictionary in the Python environment we are creating, but make
+ # a copy to prevent pyscripts from editing it. (e.g. locals().clear()). Only make a shallow copy since
+ # it's OK for py_locals to contain objects which are editable in a pyscript.
localvars = dict(self.py_locals)
localvars[self.py_bridge_name] = py_bridge
localvars['quit'] = py_quit