[Python-ideas] file API
Joao S. O. Bueno
jsbueno at python.org.br
Mon Sep 24 23:55:58 CEST 2012
On 24 September 2012 18:49, Mark Adam <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, low-level
> C-style interface for moving around in a file, with methods like
> tell() and seek(). But after attributes were introduced to Python, it
> seems like it should be re-evaluated.
>
> 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
> by the more standard and familiar 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
>
> You've now simplified the API by the removal of two obscure legacy
> methods (where one has to learn the additional concept of "absolute"
> and "relative" addressing) and replaced them with a more basic one
> called "position".
>
> Thoughts?
-1
This is not so distant from what can be achieved trivially by tell and seek.
Moreover, event though changes in attributes _can_ be made to have
side effects in Python objects, it does not mean it is easier to read and
maintain in every case.
What I think we need is a better way of dealing with constants - the "whence"
attribute for "seek" takes raw ints for "from start", "from end" and
"relative" -
but that is an entirely other subject.
js
-><-
>
> markj
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
More information about the Python-ideas
mailing list