Reading mixed ASCII/bin file-HOW?

josegomez at gmx.net josegomez at gmx.net
Fri Dec 7 09:48:26 EST 2001


In article <3C0D1D15.CA38A24B at attbi.com> you wrote:
> josegomez at gmx.net wrote:
> What's wrong with that way?? A bunch of readline() calls is exactly what
> you want. For example:

	The problem being that I am more used to Fortran than python :-)
It does indeed make sense to parse it in the way you mention (it's 
less than a hundred lines, so it is quick enough).

	So, to sum up:
	1.- Open file in binary mode
	2.- Process header by judicious readline() calls
		2.5.- Decide whether the data in the main body is 
		binary or ASCII.
	3.- Once the data header is found, either 
	        3.5a.- read binary bytes (and convert using fromstring 
		in Numeric)
		3.5b.- read ASCII data using one of the many extensions
		(either SciPy, Scientific Python), or plain vanilla
		readline() (might take a long time, though)
		3.5c.- Use a SWIG-ed C function :-)

	Thanks a lot, i have got round most problems by now, and it's
only a question of choosing the most efficient method!

	Thanks
	José
-- 
José L Gómez Dans			PhD student
Tel: +44 114 222 5582			Radar & Communications Group
FAX; +44 870 132 2990			Department of Electronic Engineering
					University of Sheffield UK



More information about the Python-list mailing list