Search code examples
pythonpydicom

What is the difference between ds.get() and ds.get_item() in pydicom


Does anyone know what is the difference in Pydicom between the two methods FileDataset.get() and FileDataset.get_item()? Thanks!


Solution

  • Both of these are not used often in user code. Dataset.get is the equivalent of python's dict.get; it allows you to ask for an item in the dictionary, but return a default if that item does not exist in the Dataset. The more usual way to get an item from a Dataset is to use the dot notation, e.g.

    dataset.PatientName
    

    or to get the DataElement object via the tag number, e.g.

    dataset[0x100010]
    

    Dataset.get_item is a lower-level routine, primarily used when there is something wrong with some incoming data, and it needs to be corrected before the "raw data element" value is converted into python standard types (int, float, string types, etc).

    When used with a keyword, Dataset.get() returns a value, not a DataElement instance. Dataset.get_item always returns either a DataElement instance, or a RawDataElement instance.