<posted & mailed>
Hi,
AFAICT there seems to be a bug on FreeBSD's Python 2.3.4 open function. The
documentation states:
[color=blue]
> Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+'
> truncates the file). Append 'b' to the mode to open the file in binary
> mode, on systems that differentiate between binary and text files (else it
> is ignored). If the file cannot be opened, IOError is raised.[/color]
Consider:
$ cat test
lalala
$ python2.3
Python 2.3.4 (#2, Jan 4 2005, 04:42:43)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
>>> f = open('test', 'r+')
>>> f.read()[/color][/color][/color]
'lalala\n'[color=blue][color=green][color=darkred]
>>> f.write('testin g')
>>> f.close()
>>>[/color][/color][/color]
[1]+ Stopped python2.3
$ cat test
lalala
-> write did not work; ok
$ fg
python2.3[color=blue][color=green][color=darkred]
>>> f = open('test', 'a+')
>>> f.read()[/color][/color][/color]
''
-> append mode does not read from file, *not ok*
[color=blue][color=green][color=darkred]
>>> f = open('test', 'w+')
>>> f.read()[/color][/color][/color]
''[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
$ cat test
-> w+ truncated file, ok
Can anyone confirm that? Is there any other way of opening a file for
appending instead of a+?
Thanks,
Ciao
Uwe
Hi,
AFAICT there seems to be a bug on FreeBSD's Python 2.3.4 open function. The
documentation states:
[color=blue]
> Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+'
> truncates the file). Append 'b' to the mode to open the file in binary
> mode, on systems that differentiate between binary and text files (else it
> is ignored). If the file cannot be opened, IOError is raised.[/color]
Consider:
$ cat test
lalala
$ python2.3
Python 2.3.4 (#2, Jan 4 2005, 04:42:43)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
>>> f = open('test', 'r+')
>>> f.read()[/color][/color][/color]
'lalala\n'[color=blue][color=green][color=darkred]
>>> f.write('testin g')
>>> f.close()
>>>[/color][/color][/color]
[1]+ Stopped python2.3
$ cat test
lalala
-> write did not work; ok
$ fg
python2.3[color=blue][color=green][color=darkred]
>>> f = open('test', 'a+')
>>> f.read()[/color][/color][/color]
''
-> append mode does not read from file, *not ok*
[color=blue][color=green][color=darkred]
>>> f = open('test', 'w+')
>>> f.read()[/color][/color][/color]
''[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
$ cat test
-> w+ truncated file, ok
Can anyone confirm that? Is there any other way of opening a file for
appending instead of a+?
Thanks,
Ciao
Uwe
Comment