Skip to content

Instantly share code, notes, and snippets.

@pythonhacker
Created January 13, 2026 07:09
Show Gist options
  • Select an option

  • Save pythonhacker/0c7e08a905dcc1c6f95940da2b817c54 to your computer and use it in GitHub Desktop.

Select an option

Save pythonhacker/0c7e08a905dcc1c6f95940da2b817c54 to your computer and use it in GitHub Desktop.
A simple Python cmd.Cmd shell supporting addition
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