0

I have a list of object as attribute of one class. When I use the __init__ method to set the list to be empyt I have an error: the list result not empty.

Here is my code:

import kittiitem as kI
class kittiFrame():
    def __init__(self, Frame="", Amount=0, Items=[], labelPath="" ):
        self.Frame = Frame
        if (Amount != len(Items)):
            print("Error in allocation.  Amount="+str(Amount)+"  Len="+str(len(Items)) )
            print(Items)  ##  !! Here print '[<kittiitem.kittiItem object at 0x7f7ce33910a0>]'
            self.Amount = 0
            self.Items = []
        else:
            self.Amount = Amount
            self.Items = Items
        if labelPath!="":
            f = open(labelPath)
            text = f.readlines()
            f.close()
            aux = labelPath.split("/")
            frameName = (aux[len(aux)-1]).split(".")[0]
            self.Frame = frameName
            for line in text:
                item=kI.kittiItem(strItem=line)
                self.Items.append(item)
                self.Amount += 1

where kittiItem is another class.

Elsewhere I invoke currFrame = kittiFrame(labelPath=currLabelPath) so I expect that default value [] is set to variable Items. On the contrary, the output is:

Error in allocation.  Amount=0  Len=1
[<kittiitem.kittiItem object at 0x7f7ce33910a0>]

Why the list is not empyt? If I substitue def __init__(self, Frame="", Amount=3, Items=[1,2,3], labelPath="" ) the list is correctly set (it breaks afterwards, due to handle int as kittiItem).

Thanks in advance

ps: for completness I attach also kittiItem class:

class kittiItem():
    def __init__(self, Frame="",  Class="", IsTruncated=0, IsOccluded=0, Alpha=0, XMin=0, YMin=0, XMax=0, YMax=0, Height3D=0, Width3D=0, Length3D=0, Location3DX=0, Location3DY=0, Location3DZ=0, Rotation_y=0, Score=0, strItem="" ):
        listItem=strItem.split(" ")
        if len(listItem) < 15:
            self.Frame = Frame
            self.Class = Class
            self.IsTruncated = IsTruncated   
            self.IsOccluded = IsOccluded
            self.Alpha = Alpha
            self.XMin = XMin
            self.YMin = YMin
            self.XMax = XMax
            self.YMax = YMax
            self.Height3D = Height3D
            self.Width3D = Width3D
            self.Length3D = Length3D
            self.Location3DX = Location3DX
            self.Location3DY = Location3DY
            self.Location3DZ = Location3DZ
            self.Rotation_y = Rotation_y
            self.Score = Score
            if strItem != "":
                print("Error in format strItem. Set default data.")
        else:
            self.Frame = Frame
            self.Class = listItem[0]
            self.IsTruncated = float(listItem[1])
            self.IsOccluded = float(listItem[2])
            self.Alpha = float(listItem[3])
            self.XMin = float(listItem[4])
            self.YMin = float(listItem[5])
            self.XMax = float(listItem[6])
            self.YMax = float(listItem[7])
            self.Height3D = float(listItem[8])
            self.Width3D = float(listItem[9])
            self.Length3D = float(listItem[10])
            self.Location3DX = float(listItem[11])
            self.Location3DY = float(listItem[12])
            self.Location3DZ = float(listItem[13])
            self.Rotation_y = float(listItem[14])
            if len(listItem) > 15:
                self.Score = float(listItem[15])
            else:
                self.Score = Score

    def show(self):
        print("Item: '"+ self.Class +"' Min=("+str(self.XMin)+" "+str(self.YMin)+")  Max=("+str(self.XMax)+" "+str(self.YMax)+")")

0 Answers0