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 >> 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. -- http://mail.python.org/mailman/listinfo/python-list