Huh. So it is; I forgot that was there. Thanks for pointing that out.
>
> So in my case I know which fields I'm modifying so I know the handful
> of Group Length tags that I might need to remove, but because I can't
> know for sure that they exist I need to wrap each del in a try-except.
> Is there a better way to handle this, for example could I get a list
> of all the Group Length tags and just remove them all?
>
I'm thinking the easiest way would be to mimic the remove_private_tags
function (in dataset.py). That is, use the dataset.walk() function and
check for any tags with element 0 and remove them. Should look
something like (untested):
def remove_grouplength_tags(ds):
def RemoveCallback(dataset, data_element):
if data_element.tag.element == 0:
del dataset[data_element.tag]
ds.walk(RemoveCallback)
Then you would be sure that they are gone from all nested datasets.
But ... if you want to do something simpler, to answer your question
about the try/except, you could test for the existence using python
'in':
if tag1 in dataset:
del dataset[tag1]
etc.
Regards,
Darcy