Created
January 13, 2026 07:09
-
-
Save pythonhacker/0c7e08a905dcc1c6f95940da2b817c54 to your computer and use it in GitHub Desktop.
A simple Python cmd.Cmd shell supporting addition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cmd | |
| import shlex | |
| class AddShell(cmd.Cmd): | |
| """ A simple cmd shell that adds numbers at the prompt """ | |
| prompt = "Add> " | |
| def default(self, arg): | |
| items = shlex.split(arg) | |
| nums = [float(i) for i in items] | |
| print(sum(nums)) | |
| def do_EOF(self, line): | |
| return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment