file position *tell()* works different
M-a-S
NO-MAIL at hotmail.com
Fri Sep 19 06:17:15 EDT 2003
More information about the Python-list mailing list
Fri Sep 19 06:17:15 EDT 2003
- Previous message (by thread): file position *tell()* works different
- Next message (by thread): file position *tell()* works different
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I'm not sure if that't the reason, but the binary mode for reading is 'rb'. Actually, the order of 'r' and 'b' shouldn't matter. But the '+' has a different meaning: the file should allow "opposite" access as well, e.g. 'r+', 'rb+' means that you can write to the file too, while 'w+' means: open it for writing but permit reading too. You can try to say 'rt' for the read/text mode. Anyway, you program works under Windows XP/Python 2.3 as expected: Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Home\Programming\Python\2>py Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>^Z C:\Home\Programming\Python\2>test.py Filepointer: 0 Filepointer: 12 Filepointer: 24 Filepointer: 35 Filepointer: 54 Filepointer: 0 Filepointer: 12 Filepointer: 24 Filepointer: 35 Filepointer: 54 I'm sorry if it doesn't help. The bug must be somewhere else then. M-a-S "Peter Abel" <p-abel at t-online.de> wrote in message news:13a533e8.0309190137.2df0cc60 at posting.google.com... > Hi all, > I'm working under W2k with > Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32 > > I have a file *test_data.txt* with the following content: > 0123456789 > 0123456789 > abcdefghi > ABCDEFGHIJKLMNOPQ > > and I work on it with the following python script: > > # Open NOT in binary mode > fp=file('test_data.txt','r') > a='xx' > while a: > print 'Filepointer: %3d' % fp.tell() > a=fp.readline() > fp.close() > > print > > # Open IN binary mode > fp=file('test_data.txt','r+b') > a='xx' > while a: > print 'Filepointer: %3d' % fp.tell() > a=fp.readline() > fp.close() > > Now, when test_data.txt is saved in PC-mode with 0xC, 0xA as newline > it works correct. > But when I save the file in UNIX-Mode with 0xA as newline, > my script gives me the following output, where that one with > the file not opened in binary mode is wrong: > Filepointer: 0 > Filepointer: 7 > Filepointer: 19 > Filepointer: 30 > Filepointer: 49 > Filepointer: 51 > > Filepointer: 0 > Filepointer: 11 > Filepointer: 22 > Filepointer: 32 > Filepointer: 50 > Filepointer: 51 > > When I try this under HP-UX it works fine in both cases. > So I wonder if the function *tell()* is not correctly implemented under win32. > > Regards > Peter
- Previous message (by thread): file position *tell()* works different
- Next message (by thread): file position *tell()* works different
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list