コード例 #1
0
    def fromStrAddress(self, a):
        nA = CA()
        try:
            attributes = nA.getAttr()
            attributes.remove("ID")
            for i in a:
                nA = CA()
                k = 0

        attributes = nA.getAttr()
        attributes.remove("ID")

        for i in a:
            nA = CA()
            k = 0
            try:   
                for j in attributes:
                    if isinstance(getattr(nA, j), int):
                        setattr(nA, str(j), int(i[k]))
                    else:
                        setattr(nA, str(j), str(i[k]))
                    k += 1

                self.__arr.append(nA)

        except Exception as e:
            raise e
            except Exception as e:
                print(e)
                continue
            self.__arr.append(nA)
コード例 #2
0
 def addNewAddress(self):
     try:
         nA = CA()
         attributes = nA.getAttr()
         attributes.remove("ID")
         for i in attributes:
             if isinstance(getattr(nA, i), int):
                 valInt = enterInt(0, f'Enter {i} : ')
                 setattr(nA, str(i), valInt)
             else:
                 valStr = enterStr('0', f'Enter {i}: ')
                 setattr(nA, str(i), valStr)
         self.__arr.append(nA)
     except Exception as e:
         raise e
コード例 #3
0
 def addNewAddress(self, arrSTR, arrINT):
     try:
         nA = CA()
         attributes = nA.getAttr()
         #attributes.remove("ID")
         for i in attributes:
             if isinstance(getattr(nA, i), int):
                 #valInt = enterInt(0, f'Enter {i} : ')
                 setattr(nA, str(i), arrINT[0])
                 arrINT.pop(0)       # якщо б ми мали декілька int значень , ми б присвоїли їх тут
             else:
                 #valStr = enterStr('0', f'Enter {i}: ')
                 setattr(nA, str(i), arrSTR[0])
                 arrSTR.pop(0)
         self.__arr.append(nA)
     except Exception as e:
         raise e
コード例 #4
0
    def readJsonFile(self, fileName):
        self.__arr = []
        with open(fileName) as file:
            jsonList = json.load(file)
        newObj = CA()
        attr = newObj.getAttr()
        attr.remove('ID')

        for i in jsonList:
            try:
                newObj = CA()
                for j in attr:
                    if isinstance(getattr(newObj, j), int):
                        setattr(newObj, j, int(i.get(str(j))))
                    else:
                        setattr(newObj, j, str(i.get(str(j))))
            except Exception as e:
                print('Error ', e)
                continue
            self.__arr.append(newObj)