python-2.1 function attributes

Emile van Sebille emile at fenx.com
Sun Jan 28 09:27:05 EST 2001


But move the function to a class and:

class G:
    def f(self):
        G.f.a = 2

works after invocation for instance.f().  With the naming
differences of methods vs functions, I like Mike Hudson's
syntactic sugar of using "." for the current
method/function, ala:

def f():
    .a = 1

class G:
    def f(self):
        .a = 2

At least when refactoring there's no ambiguity over what is
meant.  As it stands, if you try:

class G:
    def f(self):
        f.a = 2

is valid and changes f.a.

--

Emile van Sebille
emile at fenx.com
-------------------


"Moshe Zadka" <moshez at zadka.site.co.il> wrote in message
news:mailman.980662640.15627.python-list at python.org...
> On 27 Jan 2001 15:53:39 -0800, aahz at panix.com (Aahz
Maruch) wrote:
>
> > One thing I'm not clear on from all this discussion is
whether one can
> > do this:
> >
> > def f():
> >     f.a = 1
>
> Of course!
>
> Python 2.1a1 (#2, Jan 27 2001, 21:08:11)
> [GCC 2.95.3 20010111 (prerelease)] on linux2
> Type "copyright", "credits" or "license" for more
information.
> >>> def f():
> ...     f.a=1
> ...
> >>> f.a
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: a
> >>> f()
> >>> f.a
> 1
>
> --
> Moshe Zadka <sig at zadka.site.co.il>
> This is a signature anti-virus.
> Please stop the spread of signature viruses!
> Fingerprint: 4BD1 7705 EEC0 260A 7F21  4817 C7FC A636 46D0
1BD6
>





More information about the Python-list mailing list