Built-in functions and keyword arguments

J. Clifford Dyer jcd at sdf.lonestar.org
Mon Oct 29 16:58:58 EDT 2007


On Mon, Oct 29, 2007 at 06:45:22PM +0000, Duncan Booth wrote regarding Re: Built-in functions and keyword arguments:
> 
> "J. Clifford Dyer" <jcd at sdf.lonestar.org> wrote:
> 
> >> I think you are being a little bit unfair here: help(len) says:
> >> 
> >> len(...)
> >>     len(object) -> integer
> >>     
> >>     Return the number of items of a sequence or mapping.
> >> 
> >> which implies that the argument to len has the name 'object'
> >> (although in fact it doesn't have a name). The OP was simply asking
> >> about the difference in calling conventions, not proposing to write
> >> code using 'object' as the argument name.
> > 
> > Hmm....  To my mind, that just implies that the *type* of the expected
> > input is an object.  Just like the "-> integer" tells you that the
> > type of the output is an integer.  If the documentation read
> > "len(s=object) -> integer", then I would expect a keyword argument s
> > typed as an object. 
> > 
> 
> How do you interpret:
> 
> >>> help(__import__)
> Help on built-in function __import__ in module __builtin__:
> 
> __import__(...)
>     __import__(name, globals={}, locals={}, fromlist=[], level=-1) -> 
> module
> ...
> >>> help(int)
> Help on class int in module __builtin__:
> 
> class int(object)
>  |  int(x[, base]) -> integer
> ...
> 
> Can you find any case (other than a single parameter identified as 
> 'object') where you can interpret the help string as telling you the types 
> of the parameters?

OK, good point.  Perhaps it's not so specific as the type, but certainly the use of name and x in the docstrings listed above only imply something about the character of the argument, not the name of the argument itself, which is what I was trying to get at.  Help documentation for keyword arguments usually shows the argument being used as a keyword, like the example from __import__ above.

Thanks for the correction.

Cheers,
Cliff



More information about the Python-list mailing list