Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'exception.': 0.07; 'subject:file': 0.07; 'agree,': 0.09; 'eof': 0.09; 'eof,': 0.09; 'sep': 0.09; 'throw': 0.09; 'subject:python': 0.11; 'language': 0.14; 'cases': 0.15; 'result.': 0.15; '24,': 0.16; 'file;': 0.16; 'immutable,': 0.16; 'subject:API': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'byte': 0.17; 'bytes': 0.17; 'integer': 0.17; 'pointer': 0.17; 'specifies': 0.17; 'code.': 0.20; 'equivalent': 0.20; 'pos': 0.22; 'suddenly': 0.22; 'sets': 0.23; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'chris': 0.28; "i'm": 0.29; 'sense': 0.31; 'file': 0.32; 'certain': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'google': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'real': 0.61; 'making': 0.64; '100': 0.78; 'presumably': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=51EyK7B5DCNwYqV96RK+QcbEZH88TYfdjhpe6gpRNXo=; b=qaG/qXICicUeU7oxZPAnkgHqFE4zHMH9sFPI2IpJlq5iobrkAiwu/mqNy549+GhcWV /z0bSeBkxKdlTND20+03cO6pgxiHuUPtFB8Ht6vpoGZufxUV/4SGic0ocCTU0HYBqHuI 7s5WSyQ+QJ5BG9lNBM3cw3tkNE+47UY4OnAlKcHRcWnQndurPSxjNbT8tywka/IjZS03 T9Y0Kyow/mD5vq1ebYY8czRYjwUVv9d8qASDbISsIYCpY+I1UIlimNvztJBArV0EO+DP 8K7WfD6xlPsdtbMX4M3KtCdGt3+wKctFoeFnsZ/In9mWB5kbS4p7C4E5THePViHIX/0Q gTdQ== MIME-Version: 1.0 In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> From: Ian Kelly Date: Mon, 24 Sep 2012 16:37:12 -0600 Subject: Re: python file API To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348526265 news.xs4all.nl 6898 [2001:888:2000:d::a6]:38789 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29948 On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico wrote: > file.pos = 42 # Okay, you're at position 42 > file.pos -= 10 # That should put you at position 32 > foo = file.pos # Presumably foo is the integer 32 > file.pos -= 100 # What should this do? Since ints are immutable, the language specifies that it should be the equivalent of "file.pos = file.pos - 100", so it should set the file pointer to 68 bytes before EOF. > foo -= 100 # But this sets foo to the integer -68 > file.pos = foo # And this would set the file pointer 68 bytes from end-of-file. Which is the same result. > I don't see it making sense for "file.pos -= 100" to suddenly put you > near the end of the file; it should either cap and put you at position > 0, or do what file.seek(-100,1) would do and throw an exception. I agree, but the language doesn't allow those semantics. Also, what about the use of `f.seek(0, os.SEEK_END)` to seek to EOF? I'm not certain what the use cases are, but a quick google reveals that this does happen in real code. If a pos of 0 means BOF, and a pos of -1 means 1 byte before EOF, then how do you seek to EOF without knowing the file length?