Naked function call syntax

Skip Montanaro skip at pobox.com
Sat Jul 14 18:07:11 EDT 2001


>>>>> "Bengt" == Bengt Richter <bokr at accessone.com> writes:

    Bengt> Interactively, I find myself writing little things like:
    ...
    Bengt> so that, e.g., I can type

    Bengt>     pd(vars)

    Bengt> and get formatted info. But I'm lazy enough that
    Bengt> I would like to to type just
    Bengt>     pd vars

    Bengt> Is there an existing pythonic way to do this?

Not really.  However, a couple ideas come to mind.  In my .pythonrc.py file
I have

    from pydoc import help

so that I type

    help(vars)

at the interpreter prompt.

Yesterday I posted a subclass of code.InteractiveConsole that when an
attempt at evaluating user input failed, it would pass the line to
os.system:

    http://groups.google.com/groups?q=mycode.py+skip%40pobox.com&hl=en&safe=off&rnum=1&ic=1&selm=mailman.994974802.14320.python-list%40python.org

You could instead have it convert

    foo arg1 arg2 arg3

into 

    foo(arg1,arg2,arg3)

with appropriate argument quoting (checking for ints, strings and such) and
eval that.  Obviously, if arg2 contained whitespace, you'd have to quote it.
Completion of this idea is left as an exercise for the reader.

-- 
Skip Montanaro (skip at pobox.com)
(847)971-7098




More information about the Python-list mailing list