How Does Ipython's ? (question Mark) Operator Actually Work?
So i was thinking that in order to implement such a feature in a console application , where appending a question mark at the end of a function name will pour out it's doc string ,
Solution 1:
It's not done the way you're imagining. ipython reads your command prompt input as a line of text, so it has a chance to check if it ends with a question mark before it passes it on to eval
(or whatever). If it does, it runs help(name)
instead of what you typed.
AST looks a little heavy-duty, but you can get a feel for how this works by checking out the module code
. It gives you a lightweight interpreter that you can extend with syntax of this sort if you want.
Solution 2:
Have a look at the IPython.core.inputsplitter
module for the code that parses the raw input line for things like ?, !, /, %, etc.
Solution 3:
ipython uses AST, you can customize the syntax parsing and create a new ipython fork.
may help
Post a Comment for "How Does Ipython's ? (question Mark) Operator Actually Work?"