file object, details of modes and some issues.
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Fri Sep 5 07:53:05 EDT 2003
On Thu, 04 Sep 2003 23:35:11 +0100, rumours say that simon place
<simon_place at whsmithnet.co.uk> might have written:
>could someone confirm ( or otherwise ) this bug.
>manual says file.truncate leave the pointer unmoved, well it doesn't, and left
>me with a bug in a program that took a bit of finding.
> >>> f=file('test.dat','rb+')
change the above to f=file('test.dat', 'wb') to make things easier
> >>> f.write('1234567890')
> >>> f.close()
> >>> f=file('test.dat','rb+')
> >>> f.read(5)
>'12345'
> >>> f.tell()
>5L
> >>> f.truncate()
> >>> f.tell()
>10L
>( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on
>win32. )
Seems it's a Windows only bug. On a 2.4.3 linux, libc-2.2.5 the final
statement produces 5L (and the file is only 5 bytes long). Same on
another 2.4.19 libc-2.2.5, and a 2.4.21 libc-2.3.1 Linux, all with a
recent Python 2.4a0 . I did reproduce it on Windows.
I believe you should post a platform-specific bug; meanwhile, you can
assure that f.truncate() works correctly on Windows by issuing a
f.seek(f.tell()) beforehand.
--
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.
More information about the Python-list
mailing list