python gripes survey
Donn Cave
donn at u.washington.edu
Mon Aug 25 18:27:39 EDT 2003
In article <ayv2b.194710$_R5.72873618 at news4.srv.hcvlny.cv.net>,
"Ryan Lowe" <ryanlowe0 at msn.com> wrote:
> dont access the return values by their index; just unpack 'em.
>
> def getFruit() :
> return 'apples', 'oranges'
>
> apples, oranges = getFruit()
Not a solution, as he has already pointed out in another
followup. Why not
oranges, apples = getFruit()
? Well, obviously because that's wrong, but the problem
is that you may not realize it's wrong. Able to remember
the order of items in the return from posix.stat()? I am
not, and I've been using Python on UNIX for about a decade.
Here it is, in case you're wondering what I mean -
(mode, ino, dev, nlink, uid, gid, size, atime,
mtime, ctime) = os.stat('.')
So this particular case is actually resolved in 2.2 - the
return isn't really a tuple.
>>> st = os.stat('.')
>>> print st.st_uid
501
>>> type(a)
<type 'posix.stat_result'>
which is probably the best that can be done for Python.
If you were starting over from scratch, I think you'd
want to have and use a record type.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list