I’m currently making a filesystem using python-fuse and was looking up where file pointers start for each of the different modes (‘r’, ‘r+’, etc.) and found on multiple sites that the file pointer starts at zero unless it is opened in ‘a’ or ‘a+’ when it starts at the end of the file.
I tested this in Python to make sure (opening a text file in each of the modes and calling tell() immediately) but found that when it was opened in ‘a+’ the file pointer was at zero not the end of the file.
Is this a bug in python, or are the websites wrong?
For reference:
- one of the websites (search for “file pointer”)
- I am using Python 2.7.3 on Ubuntu
No, it’s not a bug.
What happens when you call
tell()after writing some data?Does it write at position 0, or at the end of file as you would expect? I would almost bet my life that it is the latter.
So, it does seek to the end of the file before it writes data.
This is how it should be. From the
fopen()man page:Phew, lucky I was right.