This discussion got me thinking and I decided to play around with
reading DICOM files using python's iterator concept, which is a very
nice feature in modern python. I've uploaded a demonstration file
"fileiter.py" to this group. It is a copy of some parts of the
filereader module, but modified to return ("yield" in a python
generator) each attribute (data element) as it is read. Using this
concept, you can read and store only certain items as you wish. The
file can be run as a script (example code in the "if __name__ ==
'__main__':" section at the end) -- the example stops reading after it
has found a certain list of items (needs python 2.5 for the "all"
function, or see the url in comments for an equivalent all() from the
python help).
This still reads the whole value of any data element it reads (rather
than delaying reading pixel data as we had talked about -- that will
come in later code) but at least you have the ability to stop before
getting to those big items if you wish.
fileiter.py is rough code, not properly tested, and I'm not sure if
files will always be closed properly, but it shows how this could be
done. I will be thinking about how to incorporate something like this
into the pydicom code. The current ReadFile function, for example,
could behave exactly as it does now, but be implemented by calling an
iterator until all items were read.