[Python-3000] enhanced descriptors, part 2

Michael Chermside mcherm at mcherm.com
Tue Jun 13 15:39:27 CEST 2006


tomer writes:
> there really is a need for "enhanced descriptors", or something like
> that. i'm having serious trouble implementing the position property,  
> as python is currently limited in this area.

No, this doesn't necessarily imply that we need "enhanced descriptors",
an alternative solution is to change the intended API for file
positions. After all, the original motivation for using a property
was that it was (a) nice to use, (b) easy to read, and (c) possible to
implement. If (c) isn't true then perhaps we rethink the API.

After all, how bad would it be to use the following:

     f.position    -- used to access the current position
     f.seek_to(x)  -- seek to an absolute position (may be relative to end)
     f.seek_by(x)  -- seek by a relative amount

Or even go half-way:

     f.position      -- used to access the current position
     f.position = x  -- seek to an absolute position (may be relative to end)
     f.seek_by(x)    -- seek by a relative amount

Properties are nice, but there's nothing wrong with methods either. If
we went with the second approach, people might foolishly use
"f.position += 4" where they intended "f.seek_by(x)" and it would still
work fine, it just wouldn't be optimized. That's really not so bad.

-- Michael Chermside



More information about the Python-3000 mailing list