[Tutor] Moving file pointer (original) (raw)
Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jul 29 23:37:01 CEST 2004
- Previous message: [Tutor] Moving file pointer
- Next message: [Tutor] How to connect a MUD client?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
You can seek() the end of the file, then use write() to output 5 zeros. Or easier open the file in append mopde and just write 5 zero bytes.
To actually write ASCII code zero you can use escaping:
zero = '\000' five-zeros = zero * 5
Alternatively you could open in binary mode and use the struct module...
As to initialising data, writing zeros is initialising it!
HTH,
Alan G
- Previous message: [Tutor] Moving file pointer
- Next message: [Tutor] How to connect a MUD client?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]