Python Strings

Alex Martelli aleaxit at yahoo.com
Wed Sep 6 08:16:19 EDT 2000


"Jonadab the Unsightly One" <jonadab at bright.net> wrote in message
news:39b5af09.17875966 at news.bright.net...
    [snip]
> > although of course the "return something()" can fail at
> > runtime if 'something', while bound to something callable
> > (a function, method, class, or instance having a __call__
> > method, for example), is not callable *without arguments*.
>
> Ah, a gotcha.  (In some languages, all functions can
> be called with no arguments.  Of course, they are not
> guaranteed to always do something useful, but that's
> the programmer's lookout.)

If you're thinking of BCPL, or Forth, yes, you can
always call anything, but you may get crashes if you
do.  In Python, you can try/except, catch the resulting
TypeError, and even, I think, parse the message "not
enough arguments; expected 1, got 0" to get a hint
about how many args you should supply (alas, it's
harder to find out automatically *WHAT* arguments
the function wants, with what meaning...:-).


Alex





More information about the Python-list mailing list