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; 'attribute': 0.05; 'case.': 0.05; 'method.': 0.05; 'exception.': 0.07; 'javascript,': 0.07; 'parameter': 0.07; 'subject:file': 0.07; 'happens.': 0.09; 'semantics': 0.09; 'sep': 0.09; 'throw': 0.09; 'subject:python': 0.11; 'bounds': 0.16; 'file;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:API': 0.16; 'wrote:': 0.17; 'byte': 0.17; 'bytes': 0.17; 'element': 0.17; 'integer': 0.17; 'pointer': 0.17; 'assignment': 0.22; 'operations.': 0.22; 'suddenly': 0.22; 'absolute': 0.23; 'sets': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'checking': 0.27; 'message-id:@mail.gmail.com': 0.27; 'arithmetic': 0.29; 'dom': 0.29; 'optional': 0.29; 'case,': 0.29; 'starts': 0.29; 'position.': 0.30; 'relative': 0.30; 'stuff': 0.30; 'sense': 0.31; 'file': 0.32; 'rid': 0.33; 'right?': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'list': 0.35; 'saved': 0.35; 'doing': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'quite': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'address': 0.60; 'different': 0.63; 'more': 0.63; 'making': 0.64; 'unusual': 0.71; '100': 0.78; 'presumably': 0.84; 'snapshot': 0.84; 'angel': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=kVxvNnm8BXyi5SOpY+RZMAxsPj89gisbMSnvIexMFAE=; b=Xav0gvPwGdw3VKdRaUBHXdjs6A6fZxueDTAt9KLB30cPZy/WI6GTw6NW5QVf1PPtk+ xnbhG2zHVF0vT8GsH22A7HR/QwYXBBnSGAKAF5b96yBnOsc2q16wGMHUAQayXdUwJCpb uNKqwkTEzlm736RvUun0dR92FStAAPyfkrbhYOeLrJNkH0WH/0MsdeF3CFCV1cNoDCxN mn9TCmhrMFtXD4n3XHB0jIaNu7Nvcf4pubiaOq6l+/C7jbdJ76DwOvG4s8B2NNxasG4q tcmgth0RjXmCQXJ6xMczRAxBr/YIMjnUmJF9p4KjDs9qwKJoJF6BOy49bDNmZRHZSNXl PHow== MIME-Version: 1.0 In-Reply-To: <5060D55C.3000407@davea.name> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Date: Tue, 25 Sep 2012 08:14:01 +1000 Subject: Re: python file API From: Chris Angelico To: python-list@python.org 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348524844 news.xs4all.nl 6900 [2001:888:2000:d::a6]:50636 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29940 On Tue, Sep 25, 2012 at 7:49 AM, Dave Angel wrote: > On 09/24/2012 05:35 PM, zipher wrote: >> Let file-type have an attribute .pos for position. Now you can get rid of the seek() and tell() methods and manipulate the file pointer more easily with standard arithmetic operations. >> >>>>> file.pos = x0ae1 #move file pointer to an absolute address >>>>> file.pos +=1 #increment the file pointer one byte >>>>> curr_pos = file.pos #read current file pointer > > And what approach would you use for positioning relative to > end-of-file? That's currently done with an optional second parameter to > seek() method. Presumably the same way you reference a list element relative to end-of-list: negative numbers. However, this starts to feel like magic rather than attribute assignment - it's like manipulating the DOM in JavaScript, you set an attribute and stuff happens. Sure it's legal, but is it right? Also, it makes bounds checking awkward: 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? 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. 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. But doing the exact same operation on a saved snapshot of the position and reassigning it would then have quite different semantics in an unusual case, while still appearing identical in the normal case. ChrisA