A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-January/042209.html below:

[Python-Dev] Re: PEP 8 addition: Preferred property style?

[Python-Dev] Re: PEP 8 addition: Preferred property style?Terry Reedy tjreedy at udel.edu
Thu Jan 22 20:46:52 EST 2004
"Gerrit Holl" <gerrit at nl.linux.org> wrote in message
news:20040122200344.GA3185 at nl.linux.org...
> Hello,
>
> currently, PEP 8 does not have any advice about the preferred style
> in defining properties. There are only two places in the standard
> library where they are used (socket.py and xml/dom/minicompat.py), so
> that doesn't provide much information either. Personally, I don't like
the
> namespace cluttering caused by defining __get, __set and/or __del. Since
> I saw someone[0] on c.l.py using it, I always use this style:
>
>     def mtime():
>         doc = "Modification time"
>
>         def get(self):
>             return os.path.getmtime(str(self))
>
>         def set(self, t):
>             return os.utime(str(self), (self.atime, t))
>
>         return get, set, None, doc
>     mtime = property(*mtime())
>
> I like it, because it's very readable for me, and doesn't clutter the
> namespace. Two questions about this style:

The 'cute' is a mental burden for the naive reader.  For compactness and no
extra name bindings, I might prefer

  def mtime():                                          # temp binding to
setter
    return os.utime(str(self), (self.atime, t)) #'return expr' is atypical

  mtime = property(
    "Modification time",
    lambda: os.path.getmtime(str(self)),
    mtime)

But I like 'def _set():...', with 'mtime =...' followed either by 'del
_set' or another 'def _set():...' even better.

Terry J. Reedy




More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4