[Tutor] Parsing DICOMRT file

Alan Gauld alan.gauld at btinternet.com
Wed Dec 12 08:15:35 CET 2007


"Bryan Fodness" <bryan.fodness at gmail.com> wrote

> First, I get different outputs from the two methods below.
>
> for line in file('file.dcm', 'rb'):
>     print line

This prints each line in turn.

> inp = open('file.dcm', 'rb')
> print inp.readlines()

This prints a list of lines

> Second, I have never tried to parse a binary file.  I could use a 
> few hints
> to get started.

Take a look at my File handling topic which gives a simple example.
(about 2/3 of the way down)

Basically the key is to know what the data looks like and define a
struct pattern to match. Note that the data may well not be
accessible using readline, you may need to use read with an length
argument. See help(read)...

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list