python file API

Chris Kaynor ckaynor at zindagigames.com
Mon Sep 24 19:14:37 EDT 2012


On Mon, Sep 24, 2012 at 3:37 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico <rosuav at 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 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.

There is no reason that it has to be an int object, however. It could
well return a "FilePosition" object which does not allow subtraction
to produce a negative result. Not saying its a good idea... Similarly,
it could be a more complex object with properties on it to determine
whether to seek from beginning or end.



More information about the Python-list mailing list