On Tue, Nov 06, 2007 at 04:21:19PM +0000, Jon Dye wrote:
On 06/11/2007, Chris G cl@isbd.net wrote:
Are there any Python people here?
How do I do the equivalent of the C below in Python :-
while ( (str = read(file)) != NULL) { do something; }
I'm not sure I understand your c example. The c read function returns the number of bytes read or -1 on an error. It's declaration is:
ssize_t read(int fd, void *buf, size_t count);
Yes, as I said before, it wasn't right, what I meant was to have the parameters as you say with a fairly small 'count'. The the loop iterates until EOF.
I can read the data OK, i.e. I have opened the file and I can successfully read from the file with the line:-
tagNum = tlvFile.read(3)
That will read at most 3 bytes from the file. If you've reached EOF then it will return the empty string. The empty string returns false if evaluated in a boolean context so:
tagNum = tlvFile.read(3) while tagNum: # do stuff with tagNum tagNum = tlvFile.read(3)
would probably work. Not sure how you are intending to handle your variable record length stuff in a while loop though.
Yes, I just don't feel those two tlvFile.read(3) calls are very elegant somehow.