On Tue, Nov 06, 2007 at 03:54:35PM +0000, Chris G 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 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)
but I don't see how to make that part of a for/while loop that exits at the end of the file. I can't use an iterator because the file is read in variable length chunks whose length depends on context.
How big a file are you talking? Why are you reading in chunks? And the C example doesn't show you reading in chunks (well, except I'm assuming that file in that instance is actually not a real file persay, but a file like object that will return data when it has it)...
Because you can do a straight read of all of the data using python using: data = fh.read()
Which would put the entire content of the file opened with filehandle fh in to data, then you can slice and dice as you like...
So, rather than give us a (very bad) C example, how about actually giving us some idea of what you're *actually* trying to do... even better with some example data file...
Believe it or not, we are not mind readers, and we can not help those that don't want it.
Thanks,