[Python-bugs-list] [ python-Bugs-432373 ] [Windows] file.tell() gives wrong value (original) (raw)

noreply@sourceforge.net noreply@sourceforge.net
Thu, 18 Oct 2001 14:04:26 -0700


Bugs item #432373, was opened at 2001-06-12 04:09 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=432373&group_id=5470

Category: Python Library Group: Platform-specific

Status: Closed Resolution: Wont Fix Priority: 3 Submitted By: Elmar Sonnenschein (eso) Assigned to: Tim Peters (timone) Summary: [Windows] file.tell() gives wrong value

Initial Comment: Invoking tell() on a file object will return a wrong (arbitrary?) value if called before seeking. Example: The following script

f = open('c:\test.xyz') print 'pos: ' + f.tell() print 'read: ' + f.read(3) print 'pos: ' + f.tell() f.seek(0) print 'pos: ' + f.tell() print 'read: ' + f.read(3) print 'pos: ' + f.tell() f.close()

will yield the following result:

pos: 0 read: XYZ pos: 3587 <-- wrong value pos: 0 read: XYZ pos: 3

Only the return value of tell is wrong, not the actual file position, i. e. a consecutive read() will return the correct bytes. It doesn't help to seek before reading, only seeking after reading will set the return value of tell() correctly.

File size of 'test.xyz' was 3.822.167 Bytes.


Comment By: Tim Peters (timone) Date: 2001-10-18 14:04

Message: Logged In: YES user_id=31435

Closing for lack of followup info requested 4 months ago.

Here's a cute file:

f = file('ga', 'wb') f.write(chr(26) * 10000) f.write('a') f.close()

If I feed that into the test program, it displays

pos: 0L read: pos: 4096L pos: 0L read: pos: 512L

under 2.2a4. But this has nothing to do with Python -- don't ever open binary files in text mode -- or, if you must, complain about the results to Microsoft .


Comment By: Tim Peters (tim_one) Date: 2001-06-13 22:48

Message: Logged In: YES user_id=31435

Changed to Platform-specific (I'm sure this doesn't happen under Unix variants).

What happens if you write this little program in C instead? My guess it will do the same thing. If so, it's a Microsoft library problem Python can't hide (Python .tell () and .seek() simply call the platform C library functions).

Reduced the priority until there's evidence this is actually a Python (not mscvrt.dll) inelegance.


Comment By: Elmar Sonnenschein (eso) Date: 2001-06-12 06:56

Message: Logged In: YES user_id=145214

Just found out that it only happens if it is a binary file which is opened without the 'b' mode flag. Therefore it is not severe but still strange behavior. Platform is Windows 2000.


Comment By: Hans Nowak (zephyrfalcon) Date: 2001-06-12 06:52

Message: Logged In: YES user_id=173607

Works fine for me... I'm using Python 2.1 on Windows NT 4, sp 5. :-/ Maybe it's platform dependent?


Comment By: Elmar Sonnenschein (eso) Date: 2001-06-12 04:15

Message: Logged In: YES user_id=145214

Checked on Python 2.0, 2.1, and ActivePython 2.1 - always the same.


You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=432373&group_id=5470