Re: python file API

2012-09-30 Thread Ramchandra Apte
On Tuesday, 25 September 2012 03:05:16 UTC+5:30, zipher wrote: For some time now, I've wanted to suggest a better abstraction for the file type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after

Re: python file API

2012-09-25 Thread Ulrich Eckhardt
Am 24.09.2012 23:49, schrieb Dave Angel: 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. Negative indices. ;) Uli -- http://mail.python.org/mailman/listinfo/python-list

Re: python file API

2012-09-25 Thread Mark Lawrence
On 25/09/2012 03:32, Mark Adam wrote: On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: There are many situations where a little bit of attribute access magic is a good thing. However, operations that involve the underlying OS and that are prone to raising

Re: python file API

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 07:25:48 +0200, Thomas Rachel wrote: Am 25.09.2012 04:28 schrieb Steven D'Aprano: By the way, the implementation of this is probably trivial in Python 2.x. Untested: class MyFile(file): @property def pos(self): return self.tell() @pos.setter

Re: python file API

2012-09-25 Thread Ian Kelly
On Mon, Sep 24, 2012 at 11:32 PM, Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de wrote: Am 25.09.2012 00:37 schrieb Ian Kelly: Since ints are immutable, the language specifies that it should be the equivalent of file.pos = file.pos - 100, so it should set the

Re: python file API

2012-09-25 Thread Oscar Benjamin
On Sep 25, 2012 9:28 AM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 25 Sep 2012 08:22:05 +0200, Ulrich Eckhardt ulrich.eckha...@dominolaser.com declaimed the following in gmane.comp.python.general: Am 24.09.2012 23:49, schrieb Dave Angel: And what approach would you use for

Re: python file API

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 08:27, Mark Lawrence breamore...@yahoo.co.uk wrote: On 25/09/2012 03:32, Mark Adam wrote: On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: try: f.pos = 256 except IOError: print('Unseekable file') Something along these

Re: python file API

2012-09-25 Thread Mark Lawrence
On 25/09/2012 11:38, Oscar Benjamin wrote: On 25 September 2012 08:27, Mark Lawrence breamore...@yahoo.co.uk wrote: On 25/09/2012 03:32, Mark Adam wrote: On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: try: f.pos = 256 except IOError:

Re: python file API

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 11:51, Mark Lawrence breamore...@yahoo.co.uk wrote: On 25/09/2012 11:38, Oscar Benjamin wrote: On 25 September 2012 08:27, Mark Lawrence breamore...@yahoo.co.uk wrote: On 25/09/2012 03:32, Mark Adam wrote: On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin

Re: python file API

2012-09-25 Thread Thomas Rachel
Am 25.09.2012 10:13 schrieb Dennis Lee Bieber: Or some bit setting registers, like on ATxmega: OUT = 0x10 sets bit 7 and clears all others, OUTSET = 0x10 only sets bit 7, OUTTGL = 0x10 toggles it and OUTCLR = 0x10 clears it. Umpfzg. s/bit 7/bit 4/. I don't think I'd want to work with

Re: python file API

2012-09-25 Thread Grant Edwards
On 2012-09-25, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 25 Sep 2012 08:22:05 +0200, Ulrich Eckhardt ulrich.eckha...@dominolaser.com declaimed the following in gmane.comp.python.general: Am 24.09.2012 23:49, schrieb Dave Angel: And what approach would you use for positioning

Re: python file API

2012-09-25 Thread Chris Angelico
On Wed, Sep 26, 2012 at 2:07 AM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: f.pos += delta would be a seek.set and with a naive driver might trigger a rewind to the start of the tape followed by a seek to the absolute position, whereas the seek from current location would only

Re: python file API

2012-09-25 Thread Thomas Rachel
Am 25.09.2012 09:28 schrieb Steven D'Aprano: The whole concept is incomplete at one place: self.seek(10, 2) seeks beyond EOF, potentially creating a sparse file. This is a thing you cannot achieve. On the contrary, since the pos attribute is just a wrapper around seek, you can seek beyond EOF

python file API

2012-09-24 Thread zipher
For some time now, I've wanted to suggest a better abstraction for the file type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after attributes were introduced to Python, it seems it should be re-addressed.

Re: python file API

2012-09-24 Thread Dave Angel
On 09/24/2012 05:35 PM, zipher wrote: For some time now, I've wanted to suggest a better abstraction for the file type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after attributes were introduced to

Re: python file API

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 22:35, zipher dreamingforw...@gmail.com wrote: For some time now, I've wanted to suggest a better abstraction for the file type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after

Re: python file API

2012-09-24 Thread Chris Kaynor
On Mon, Sep 24, 2012 at 2:49 PM, Dave Angel d...@davea.name wrote: 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. I'm not advocating for or against the idea, but that could be handled the

Re: python file API

2012-09-24 Thread Chris Angelico
On Tue, Sep 25, 2012 at 7:49 AM, Dave Angel d...@davea.name 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.

Re: python file API

2012-09-24 Thread zipher
You raise a valid point: that by abstracting the file pointer into a position attribute you risk de-coupling the conceptual link between the underlying file and your abstraction in the python interpreter, but I think the programmer can take responsibility for maintaining the abstraction. The

Re: python file API

2012-09-24 Thread Dave Angel
(forwarding to the list) On 09/24/2012 06:23 PM, Mark Adam wrote: On Mon, Sep 24, 2012 at 4:49 PM, Dave Angel d...@davea.name wrote: On 09/24/2012 05:35 PM, zipher wrote: For some time now, I've wanted to suggest a better abstraction for the file type in Python. It currently uses an

Re: python file API

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico ros...@gmail.com 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

Re: python file API

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 23:41, Mark Adam dreamingforw...@gmail.com wrote: seek() and tell() can raise exceptions on some files. Exposing pos as an attribute and allowing it to be manipulated with attribute access gives the impression that it is always meaningful to do so. It's a good

Re: python file API

2012-09-24 Thread Chris Angelico
On Tue, Sep 25, 2012 at 8:37 AM, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico ros...@gmail.com 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

Re: python file API

2012-09-24 Thread Mark Lawrence
On 24/09/2012 22:35, zipher wrote: For some time now, I've wanted to suggest a better abstraction for the file type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after attributes were introduced to Python,

Re: python file API

2012-09-24 Thread Chris Kaynor
On Mon, Sep 24, 2012 at 3:37 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico ros...@gmail.com 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

Re: python file API

2012-09-24 Thread Steven D'Aprano
On Tue, 25 Sep 2012 08:14:01 +1000, Chris Angelico wrote: 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

Re: python file API

2012-09-24 Thread Steven D'Aprano
On Mon, 24 Sep 2012 15:36:20 -0700, zipher wrote: You raise a valid point: that by abstracting the file pointer into a position attribute you risk de-coupling the conceptual link between the underlying file and your abstraction in the python interpreter I don't think this argument holds

Re: python file API

2012-09-24 Thread Mark Adam
On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: There are many situations where a little bit of attribute access magic is a good thing. However, operations that involve the underlying OS and that are prone to raising exceptions even in bug free code should not

Re: python file API

2012-09-24 Thread Thomas Rachel
Am 25.09.2012 04:28 schrieb Steven D'Aprano: By the way, the implementation of this is probably trivial in Python 2.x. Untested: class MyFile(file): @property def pos(self): return self.tell() @pos.setter def pos(self, p): if p 0:

Re: python file API

2012-09-24 Thread Thomas Rachel
Am 25.09.2012 00:37 schrieb Ian Kelly: On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelicoros...@gmail.com 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?