Naked function call syntax
Patrick K. O'Brien
pobrien at orbtech.com
Sun Jul 15 19:35:24 CEST 2001
Here is a class that might give you some ideas. If you combined this with
raw_input('What do you want to pd?') as the method you might get something
close to what you want. I haven't actually used this class with something
that needed a parameter but it should be doable.
'''A callable class that implements a method that is passed as a
Good for creating a pseudo keyword in the python runtime environment.
keyword is really an object that has a repr() that calls itself which
the method that was passed in the init of the object. All this just to
having to type in the closing parens on a method. So, for example:
>>> quit = PseudoKeyword(SomeObject.someMethod)
SomeObject.someMethod gets executed as if it had been called directly
the user didn't have to type the parens, like "quit()". This technique
most applicable for pseudo keywords like quit, exit and help.
def __init__(self, method):
# XXX Should probably check that this is a callable object.
self.method = method
Patrick K. O'Brien
"I am, therefore I think."
"Bengt Richter" <bokr at accessone.com> wrote in message
news:3b4fa037.1845423078 at wa.news.verio.net...
> Interactively, I find myself writing little things like:
> def pd(x):
> print x.__doc__
> print '(no doc string)'
> so that, e.g., I can type
> and get formatted info. But I'm lazy enough that
> I would like to to type just
> pd vars
> Is there an existing pythonic way to do this?
> If not, would there be breakage if python were modified to make
> foo whatever-up-to-EOL
> equivalent to
> when it would be a syntax error otherwise? I.e., I'm wondering
> if the grammar could be modified to do this by changing trailer
> to accept arglist NEWLINE if _all_ else fails, and treat a match
> as if it was an arglist. Leading '(' or '[' ambiguity would be
> resolved in favor of normal arglist or subscriptlist.
More information about the Python-list