A python beginner here. Sorry if this question is dumb. I am simply trying to access an instance classes' method ( addComponentToIC ) via a "variablized" object/instance name read in from a dictionary.
I create a dictionary looks like this:
qaDict = {} # a place to store the DSIDs/names for later use
jd = r.findDSIDs('My QA Team', 'External') # make the call to get unique IDs
for a in jd:
(a['lastName']).lower() + '_' + (a['firstName']).lower() #name the object using "last_name_firstName"
if a['dsid'] not in blacklistedDSIDs:
globals()[qaperson] = Ic(a['dsid'], a['lastName'], a['firstName']) ## create the Ic object
qaDict[a['dsid']] = qaperson ## add person to list of DSIDs
Then I want to take those IDs and grab all the components they are verifier on:
for key, value in qaDict.items():
jd = r.findComponents(key)
getattr(value, 'addComponentToIC')(jd['id'], jd['name'])
I get a : AttributeError: 'unicode' object has no attribute 'addComponentToIC'
I have also tried:
for key, value in qaDict.items():
jd = r.findComponents(key)
value.addComponentToIC(jd['id'], jd['name'])
That also throws the same error. So it seems like it's something to do with the variable name "value", not actually being interpreted as the instance name. It is supposed to wind up looking like:
employees_name.addComponentToIC(jd['id'], jd['name'])
-- where "employees_name" is an instance of the class previously created, but it doesn't work. I know there is something silly I am not understanding here ;-) Any help would be greatly appreciated!
My Class looks like this:
class Ic(object):
'This is a class for QA folks'
empCount = 0
@classmethod
def displayEmployeeCount(class_obj):
print ("The total employee count is %d" % Ic.empCount)
def __string__(self):
return str(self)
def __init__(self, dsid, fname, lname):
self.dsid = dsid
self.fname = fname
self.lname = lname
self.name = fname + ' ' + lname
Ic.empCount += 1
self.ticketCount = 0
self.componentCount = 0
self.componentDict = {}
self.componentName = ''
#Ic.instances.add(self)
def addComponentToIC(self, componentID, componentName):
self.componentName = componentName
self.componentID = componentID
self.componentDict[componentID] = componentName
@classmethod
def get_instances(cls):
return list(Ic.instances)
def addTicketCount(self, count):
self.ticketCount += count
def addComponentCount(self, count):
self.componentCount += count
def displayComponentNumber(self):
print (self.name, " has ", len(self.componentDict), " number of components.")
def displayEmployee(self):
print ("Name: ", self.name, "DSID: ", self.dsid, "Count: ", self.ticketCount, ", Component Count: ", len(self.componentDict))
def displayComponentDict(self):
print ("This employee is verifier for the following components: ", self.componentDict)