when i use pydicom, errror printed..IndexError: list index out of range

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



when i use pydicom, errror printed..IndexError: list index out of range



Using pydicom to try to read a test file like so:


from pydicom.data import get_testdata_files

pass_dicom = "CT-MONO2-16-ankle.dcm"
filename = get_testdata_files(pass_dicom)[0]



I get an error


Traceback (most recent call last):
File "t.py", line 4, in <module>
filename = get_testdata_files(pass_dicom)[0]
IndexError: list index out of range



Please help.





Please provide the code as actual text and not an image of it.
– Shai
Aug 13 at 8:33





I edited your question to include the code, as @Shai suggested. Note that it was not a great question in other ways - there was no indication of what you'd tried, and there reproductoin code included some extraneous elements. Please consider reading and applying stackoverflow.com/help/how-to-ask when asking your next question. It will help the answerers help you.
– Blair Conrad
2 days ago




1 Answer
1



get_testdata_files looks for files in libsite-packagespydicomdatatest_files under your python installation.


get_testdata_files


libsite-packagespydicomdatatest_files



"CT-MONO2-16-ankle.dcm" does not appear to be one of the supplied sample files (at least I don't have it with pydicom 1.1.0). So get_testdata_files is returning an empty list () and when you try to get the 0th item, it raises an exception because there is no 0th item.




In the future, when debugging these kinds of errors, consider decomposing your code. Once you find a problem with get_testdata_files(pass_dicom)[0], try get_testdata_files(pass_dicom). See what its result is, and why.


get_testdata_files(pass_dicom)[0]


get_testdata_files(pass_dicom)



And remember, the pydicom source is available online and installed on your own computer, so you can always see (for example) what get_testdata_files is trying to do.


get_testdata_files






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard