[Tutor] Moving file pointer

orbitz orbitz at ezabel.com
Thu Jul 29 23:17:18 CEST 2004


 From file objects documentation:

*truncate*( 	[size])

    Truncate the file's size. If the optional size argument is present,
    the file is truncated to (at most) that size. The size defaults to
    the current position. The current file position is not changed. Note
    that if a specified size exceeds the file's current size, the result
    is platform-dependent: possibilities include that file may remain
    unchanged, increase to the specified size as if zero-filled, or
    increase to the specified size with undefined new content.
    Availability: Windows, many Unix variants.


Bob Gailer wrote:

> At 12:03 PM 7/29/2004, Gus Tabares wrote:
>
>> I'm trying to set the file pointer for a file on a posix machine. For
>> instance, I have a simple 5-byte file with data 'abcde'. I want to
>> 'extend' the file to 10-bytes, but not initialize any data in those
>> extra 5-bytes. They should be all zeros.
>>
>> This is analogous to win32file.SetFilePointer routine.
>>
>> Does anyone have any pointers (no pun intended) to a solution?
>
>
> We have no OBJECTion to puns. And Python is a pointerless language ( 
> or else its all pointers under the covers ).
>
> Best I can think of is to write 5 zero bytes at the end of the file.
>
> Bob Gailer
> bgailer at alum.rpi.edu
> 303 442 2625 home
> 720 938 2625 cell
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



More information about the Tutor mailing list