Search code examples
pythonintdicompydicom

Trouble finding certain tag values


I'm trying to find the value of several tags using pydicom. For some reason only certain tags work while others do not. Below is a traceback explaining my problem. Can anyone see a way around the int() base 16 problem?

>>> ds['0x18','0x21'].value
'SP'
>>> ds['0x18','13x14'].value
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/space/jazz/1/users/gwarner/anaconda/lib/python2.7/site-packages/pydicom-0.9.9-py2.7.egg/dicom/dataset.py", line 276, in __getitem__
tag = Tag(key)
  File "/space/jazz/1/users/gwarner/anaconda/lib/python2.7/site-packages/pydicom-0.9.9-py2.7.egg/dicom/tag.py", line 27, in Tag
arg = (int(arg[0], 16), int(arg[1], 16))
ValueError: invalid literal for int() with base 16: '13x14'

Solution

  • '13x14' is not a valid representation of base 16 number.

    In python, base 16 numbers are represented with '0x' as prefix and then the number in base 16.

    For example:

    0x0, 0x1, 0x001, 0x235, 0xA5F, ..., are all valid base 16 number representations.


    This:

    ds['0x18','13x14'].value
    

    Could be, for example, this:

    ds['0x18','0x14'].value
    

    And it should execute fine.