本文整理汇总了Python中Person.Person.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Python Person.setAttribute方法的具体用法?Python Person.setAttribute怎么用?Python Person.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person.Person
的用法示例。
在下文中一共展示了Person.setAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import setAttribute [as 别名]
def read(fName):
Log.trace(__class__, "read()")
pCollection = PersonCollection()
try:
file = open(fName, 'r')
isHeader = True
#SEP = ',*'
SEP = "[\,,\s]*"
EMB = "\""
regEx = re.compile(EMB + '([^' + EMB + ']*)' + EMB + SEP)
for line in file:
i = 0
person = Person()
for col in regEx.findall(line):
if(isHeader):
pCollection.addHeader(col)
#self._headerNames.append(col)
else:
person.setAttribute(pCollection.getHeaderNames()[i], col)
i += 1
if(isHeader):
isHeader = False
else:
pCollection.addPerson(person)
file.close()
return pCollection
except IOError:
Log.error(__class__, "IOError with file > " + fName)
return None
示例2: _merge
# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import setAttribute [as 别名]
def _merge(pcMerge, pcMaster, pcSlave):
Log.trace(__class__, "_merge() called")
# add headerNames in pcNew
for kMaster in pcMaster.getHeaderNames():
pcMerge.addHeader(kMaster)
# Merge attributes of pcMaster to pcNew
for pMaster in pcMaster.getPersons():
pMerge = Merge.getPerson(pcMerge, pMaster)
if(pMerge == None):
pMerge = Person()
pcMerge.addPerson(pMerge)
pSlave = Merge.getPerson(pcSlave, pMaster)
if(pSlave == None):
# do copy of pMaster
pSlave = Person()
for kMaster in pcMaster.getHeaderNames():
aMaster = pMaster.getAttribute(kMaster)
aSlave = pSlave.getAttribute(kMaster)
aMerge = Person.ATTR_NOT_AVAILABLE
# Attribute is empty
if((aMaster != "" or aMaster != Person.ATTR_NOT_AVAILABLE) and (aSlave == "" or aSlave == Person.ATTR_NOT_AVAILABLE)):
aMerge = aMaster
elif((aSlave != "" or aSlave != Person.ATTR_NOT_AVAILABLE) and (aMaster == "" or aMaster == Person.ATTR_NOT_AVAILABLE)):
aMerge = aSlave
# Attributes are not empty
elif(aMaster == aSlave):
aMerge = aMaster
else:
Log.warn(__class__, "merge conflict:\nMaster=" + aMaster + "\n Slave=" + aSlave)
pMerge.setAttribute(kMaster, aMerge)
Log.trace(__class__, "_merge() finished")
示例3: doMapping
# 需要导入模块: from Person import Person [as 别名]
# 或者: from Person.Person import setAttribute [as 别名]
def doMapping(self, pcSrc):
pcDest = PersonCollection()
# add headerNames to destination personCollection
for kDest in self._mapping.values():
pcDest.addHeader(kDest)
# add srcPersons to destPersons with new headerNames
for pSrc in pcSrc.getPersons():
pDest = Person()
for kSrc, kDest in self._mapping.items():
attr = pSrc.getAttribute(kSrc)
if((attr == Person.ATTR_NOT_AVAILABLE or attr == "") and self._defaultValues[kDest] != ""):
attr = self._defaultValues[kDest]
pDest.setAttribute(kDest, attr)
pcDest.addPerson(pDest)
return pcDest