Python Forum
Using variables as the assigned value and not the string
Thread Rating:
  • 3 Vote(s) - 2.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using variables as the assigned value and not the string
#11
I have moved further in this script and changed it a bit. Now I am importing data from a text file and comparing my dicom data to the values in the text file. I ran into another similar issue that I have not been able to solve.
import dicom
import os
import numpy
from matplotlib import pyplot, cm
 
 
epi_hd = dicom.read_file("epi/i00001.1")
 
 
def getVarFromFile(epi_template2):
    import imp
    f = open(epi_template2)
    global data
    data = imp.load_source('data', '', f)
    f.close()
 
getVarFromFile('/path/to/epi_template2')
parameters = "SAR", "Rows", "Modality", "Columns"
for parameter in parameters:
    if (epi_hd.data_element(parameter).value) != (data.parameter):
        print("%s: EPI PARAMETER MISMATCH!!!!!") % parameter 
The issue is with looping through the parameter values.

(epi_hd.data_element(parameter).value) gives me the correct value

but...

(data.parameter) is not recognized even though data.SAR returns the correct value.

error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'parameter'

Does anyone have any helpful suggestions?

Thanks a lot
Reply
#12
Looks like data is a module that doesn't contain anything called "parameter".
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020