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);
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.
JD