By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

Cross-platform issues with file's a+ mode

P: n/a
I was helping someone debug his code today .. it worked fine on Linux, but
gave a strange error message on Windows. Here's the snippet that goes
wrong in Python 2.2 under Windows (it also happens under 2.3a1 under
Windows and Enthought's 2.3.3, so I think it's pretty generic) .. :
f = file('test.txt','a+')
f.readline() '' f.write('beep') Traceback (most recent call last):
File "<pyshell#48>", line 1, in ?
IOError: (0, 'Error')

but .. I can make things work by seeking:

I don't know whether it's important or not, but if I do an f.tell() after
the readline(), it says 0L, which seems reasonable.

For comparison (and this is also true under, e.g., Linux 2.3a1),

bash-2.04$ python
Python 2.2 (#1, Feb 18 2002, 14:48:51) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information. import os
f = file('test.txt','a+')
f.readline() '' f.write('beep')

What's going on here? Should I expect this behavior? I've never needed
to use a+ mode before .. is it just known to be funny or have interesting
cross-platform issues?


Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.