python file API
Oscar Benjamin
oscar.j.benjamin at gmail.com
Mon Sep 24 17:56:35 EDT 2012
More information about the Python-list mailing list
Mon Sep 24 17:56:35 EDT 2012
- Previous message (by thread): python file API
- Next message (by thread): python file API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 24 September 2012 22:35, zipher <dreamingforward at 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 attributes were introduced to Python, it seems it should be > re-addressed. > > 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 > 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. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20120924/a7017434/attachment.html>
- Previous message (by thread): python file API
- Next message (by thread): python file API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list