I wanted to see if it was possible to define new keywords or, as they're called in WAT's Destroy All Software talk when discussing Ruby, bare words, in Python.
I came up with an answer that I couldn't find elsewhere, so I decided to share it Q&A style on StackOverflow.
I've only tried this in the REPL, outside any block, so far. It may be possible to make it work elsewhere, too.
I put this in my python startup file:
Quick REPL session demonstration afterwords:
Use responsibly.
Edit: Here's a more useful example. I added in a
run
keyword.atPrompt.autoRun
is a list of variables that, when my prompt is displayed, will automatically be checked and fed back. So, for example, I can do this:And this gets interpreted as:
It's kind of like a macro - it's common for me to want to do this kind of thing, so I decided to add in a keyword that lets me do it in fewer keystrokes.