the annoying, verbose self

Iain King iainking at gmail.com
Tue Nov 27 07:19:04 EST 2007


On Nov 27, 12:03 pm, Duncan Booth <duncan.bo... at invalid.invalid>
wrote:
> Iain King <iaink... at gmail.com> wrote:
> > FTR, I won't be using this :)  I do like this syntax though:
>
> > class Vector:
> >     def __init__(self, x, y, z):
> >         self.x = x
> >         self.y = y
> >         self.z = z
> >     def abs(self):
> >         using self:
> >             return math.sqrt(.x*.x + .y*.y + .z*.z)
>
> It is a bit verbose though. This variant is shorter on my system[*]:
>
> class Vector:
>     def __init__(self, x, y, z):
>         self.x = x
>         self.y = y
>         self.z = z
>     def abs(self):
>         return math.sqrt(self.x*self.x + self.y*self.y + self.z*self.z)
>
> [*] Windows, they are the same length on Linux.
>
> :)

Yeah, in this example.  Another would be

using NetworkConnection:
    .address = "127.0.0.1"
    .port = "8080"
    .connect()
    using .connection
       while .read():
           do something
    .disconnect()

I doubt anything like this will take though, since you can write
similar code with 'with' and assigning a long name to a short one.

Iain




More information about the Python-list mailing list