I try to make game in python using pygame. It should be learning game, so I want to ask if it is possible to run python shell in game window or I have to program my own parser?
1 Answer
subprocess.Popen('python') will open a Python interpreter in a new window, similar to typing 'python' on a command line. But I suspect that this is not what you meant by 'in a game window'.
cmd.Cmd creates "A simple framework for writing line-oriented command interpreters" (that use verb object... syntax). It could be used for writing a text adventure game ('go east', 'open box', 'look room', etc).
code.InteractiveInterpreter is specifically for Python interpreters. It uses compile and exec. Idle's Shell is based on a subclass thereof defined in idlelib/PyShell.py. It simulates the Python interactive interpreter in a tkinter window. There is no need to re-write the parser included in compile; one can tell compile to stop with the abstract syntax tree that is the output of the parser.
eval(),exec()functions.python3 -midlelibis implemented in Python.cmdmodule to create an interactive shell, and/or write a small parser for a DSL.python3 -midlelibexample makes it clear: what type of "python shell" I'm talking about. btw, I don't see security or performance mentioned in eval/exec docs. You could submit a documentation patch that discusses them (in a separate section with links from the corresponding functions).