Re: [Python-Dev] [Python-checkins] r53110 - python/trunk/Lib/mailbox.py
On Thu, Dec 21, 2006 at 02:14:55AM -0500, Fred L. Drake, Jr. wrote:
I (only vaguely) recall Guido telling people that that's how it's documented, and that's what they should use. Don't know if he still feels that way; if he's recanted the obscure path, we can fix both the calls and the documentation. I'd lend a hand!
The constants were added in 2.5. I've gone ahead and made the documentation change to trunk and 25-maint, because why were the constants added if they weren't intended to be used? While looking at the code, I noticed a minor potential bug. Python defines SEEK_SET and friends to be 0,1,2 and then os.lseek() maps them to SEEK_SET, SEEK_CUR, SEEK_END. file.seek() does *not* do this; it just passes the 0,1,2 through to the stdio fseek(), and therefore would be broken if there's some weird platform where 0,1,2 aren't the correct values. This doesn't seem worth fixing, given that no one has ever run into it, and might be an argument for removing the conversion from os.lseek(); clearly it isn't needed. --amk
A.M. Kuchling schrieb:
The constants were added in 2.5. I've gone ahead and made the documentation change to trunk and 25-maint, because why were the constants added if they weren't intended to be used?
See #711830. They were added for compatibility (with earlier Python releases) primarily. Some people believe in these constants, so just let them have them. Python (the API) doesn't really rely on them, but instead guarantees that the numeric values are always the same across platforms. Now it seem that introducing them has the unfortunate side effect that people think they *have* to use them, and that doing so gives better code... Regards, Martin
On Thursday 21 December 2006 15:23, Martin v. Löwis wrote:
Now it seem that introducing them has the unfortunate side effect that people think they *have* to use them, and that doing so gives better code...
Speaking strictly for myself: I don't think I *have* to use them, but I do prefer to use them because I don't like magic constants that affect what a function does in code; I'd rather have a named constant for readability's sake. Maybe I just can't keep enough in my head, but I don't find I actually use seek() enough to remember what the numeric values mean with checking the reference documentation. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org>
Fred L. Drake, Jr. schrieb:
Speaking strictly for myself: I don't think I *have* to use them, but I do prefer to use them because I don't like magic constants that affect what a function does in code; I'd rather have a named constant for readability's sake. Maybe I just can't keep enough in my head, but I don't find I actually use seek() enough to remember what the numeric values mean with checking the reference documentation.
But you *can* remember the symbolic names (plus you can remember what module they are in, in what Python version)? I'd have to consult the documentation for either; help(file.seek) gives the numeric values. Regards, Martin
On 12/29/06, "Martin v. Löwis"
Fred L. Drake, Jr. schrieb:
Speaking strictly for myself: I don't think I *have* to use them, but I do prefer to use them because I don't like magic constants that affect what a function does in code; I'd rather have a named constant for readability's sake. Maybe I just can't keep enough in my head, but I don't find I actually use seek() enough to remember what the numeric values mean with checking the reference documentation.
But you *can* remember the symbolic names (plus you can remember what module they are in, in what Python version)? I'd have to consult the documentation for either; help(file.seek) gives the numeric values.
I'm with Martin here. But my main objection to suggesting that these constants ought to be used is that open() is a built-in but you would have to import os to be able to call the seek method on the object it returns. If we want to make the seek API more 21st century, why not use keyword arguments? -- --Guido van Rossum (home page: http://www.python.org/~guido/)
On Friday 29 December 2006 16:55, Guido van Rossum wrote:
If we want to make the seek API more 21st century, why not use keyword arguments?
I'd prefer that myself. I'm not advocating the constants as a way to go forward, but was simply expressing a preference for the named constant over a magic number in code. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Dec 29, 2006, at 4:55 PM, Guido van Rossum wrote:
But my main objection to suggesting that these constants ought to be used is that open() is a built-in but you would have to import os to be able to call the seek method on the object it returns.
If we want to make the seek API more 21st century, why not use keyword arguments?
Or put the constants on class attributes. - -Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin) iQCVAwUBRZWRM3EjvBPtnXfVAQLWdwQAmrt5ncAhFIxCK2Tm72g90P9qckVrkdAt odvZ+fw8RFrKs3MUpsP2HtfHWHrouC6SHQCXoU63msfgy52vO4M9rG3NLN5Hi0KK tU4J9pkSqqi+Jfu4LvCs+ouURqxTbGicyMBUuw54hQWqg0bxvYvjEyuC1NFltcV6 HJ2qElSTOw0= =LAq1 -----END PGP SIGNATURE-----
participants (5)
-
"Martin v. Löwis"
-
A.M. Kuchling
-
Barry Warsaw
-
Fred L. Drake, Jr.
-
Guido van Rossum