def do_py(self, arg):
        """
        ::

            Usage:
                py
                py COMMAND

            Arguments:
                COMMAND   the command to be executed

            Description:

                The command without a parameter will be executed and the
                interactive python mode is entered. The python mode can be
                ended with ``Ctrl-D`` (Unix) / ``Ctrl-Z`` (Windows),
                ``quit()``,'`exit()``. Non-python commands can be issued with
                ``cmd("your command")``.  If the python code is located in an
                external file it can be run with ``run("filename.py")``.

                In case a COMMAND is provided it will be executed and the
                python interpreter will return to the command shell.

                This code is copied from Cmd2.
        """
        self.pystate['self'] = self
        arg = arg.strip()
        localvars = (self.locals_in_py and self.pystate) or {}
        interp = InteractiveConsole(locals=localvars)
        interp.runcode('import sys, os;sys.path.insert(0, os.getcwd())')
        if arg:
            interp.runcode(arg)
        else:
            def quit():
                raise EmbeddedConsoleExit

            def onecmd(arg):
                return self.onecmd(arg + '\n')

            def run(arg):
                try:
                    f = open(arg)
                    interp.runcode(f.read())
                    f.close()
                except IOError, e:
                    self.perror(e)
            self.pystate['quit'] = quit
            self.pystate['exit'] = quit
            self.pystate['cmd'] = onecmd
            self.pystate['run'] = run
            try:
                cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
                keepstate = Statekeeper(sys, ('stdin', 'stdout'))
                sys.stdout = self.stdout
                sys.stdin = self.stdin
                interp.interact(banner="Python %s on %s\n%s\n(%s)\n%s" %
                                (sys.version, sys.platform, cprt, self.__class__.__name__, self.do_py.__doc__))
            except EmbeddedConsoleExit:
                pass
            keepstate.restore()