python-2.1 function attributes

Carel Fellinger cfelling at iae.nl
Wed Jan 24 16:06:35 EST 2001


Michael Hudson <mwh21 at cam.ac.uk> wrote:
> Mike Romberg <romberg at smaug.fsl.noaa.gov> writes:

>>   I've been messing around with python-2.1a1 and have discovered the
>> new feature 'function attributes'.  The project I'm currently working
>> on can really use this feature.  The feature itself would be much more
>> useful if one could predefine a set of attributes with the function
>> definition.  This is one of the things mentioned in the 'future
>> directions' sections of pep 232 
>> 
>> http://python.sourceforge.net/peps/pep-0232.html
>> 
>>   So... I guess I'd like to put in one 'yes' vote for this extension :).

> I suspect if you can come up with a decent syntax, it will go in.  I
> can't though.  Any ideas?

I'm always full of ideas, whether they make sence...

in current Python (1.5, 2.0) you can do:

    >>> def f():
    ...     'spam'
    ...     print f.__doc__
    ...     f.__doc__ = f.__doc__ + ' and spam'
    ...
    >>> f()
    spam
    >>> f()
    spam and spam

why not enhance this like in:

    >>> def f()
    ...     with:
    ...         f.__doc__ = 'spam'
    ...     print f.__doc__
    ...     f.__doc__ = f.__doc__ + ' and spam'
    ...
    >>> f()
    spam
    >>> f()
    spam and spam

and play some tricks to allow "with: suit" only here without it being
a true keyword.
-- 
groetjes, carel



More information about the Python-list mailing list