How to I remove or update data (not objects) in a class list?

I created the following class:

class myAIS():
    def __init__(self, mmsi, Alat, Alon, Aspeed, Acourse, shipname):
        self.mmsi=mmsi         #integer
        self.lat=Alat          #float 
        self.lon=Alon          #float
        self.speed=Aspeed      #float
        self.Acourse=Acourse   #float
        self.name=shipname     #string

This is used to store the current key information on every ship that I am detecting using an AIS receiver. The list variable AISList is then populated with all the ships as I receive their unique ID (MMSI).

AISList.append(myAIS(dm.mmsi, LatAIS, LonAIS, SpdAIS, CourseAIS, ShipName))

As I said, this allows me to store the current key information on each ship. I in fact, use this information to plot the ship positions on a map. However, as a ship moves, its new position is broadcast. So I need to constantly check that any new information received for existing ships are updated. If it is a new ship, then it is just appended as shown above.

I have successfully been able to identify when a ship is new to the list or if it is just an update. My issue is the method required to UPDATE the list. My approach was to simply delete the older instance of the ship in the list, and append the UPDATE to the bottom of the list. There were 2 reasons I used this approach: (1) it seemed easier [but turned out not to be] (2) I have a second list that stores the markers (symbols) for the map. That list is easily modified by this method (delete the repeating index and then use append to add the new instance).

This is the issue — how to I delete a AISList[j] from the list, where j is the index of the older instance? For example, if j = 8, how do I delete AISList[j].mmsi, AISList[j].Alat, AISList[j].Alon,...,AISList[j].shipname? Should I try using something other than a class list?

I have tried AISList.pop(j), AISList[j].remove(), and delete(), and every perceivable combination thereof. Desperation led to trying absurd combinations of AISList and myAIS with pop, remove, and delete. I get errors with every attempt.

I’ve searched stackoverflow (as well as many other sites) for answers, but most answers focus on removing an object, like AISList.course. But I don’t need to remove the object. I just need to remove the AISList[j] instance.

Any help would be grateful.

Here is the code section I’m working on:

                try:            
                    Alength = len(AISList)
                    if Alength>0:
                        print("AISList length = ", Alength)
                        #print("AISList = ", AISList)
                        print("dm.mmsi = ", dm.mmsi)
                        for j in range(0,Alength):
                            readmmsi=int(dm.mmsi)
                            readAISList=AISList[j].mmsi
                            if readmmsi == readAISList:
                                **AISv.pop(j)    
                                AISList.pop(j)**                               
                except Exception as e:
                    print("AISList error = ", e)
                    pass
                
                #Now add the latest ship information to the lists
                #This the AISv list is the set of markers plotted
                #on the TkMapView map.  
                try:
                    LatAIS=float(dm.lat)
                except ValueError as e:
                    latAstr= dm.lat     # can't take the float of a negative string
                    latAstr=latAstr[1:]  #remove minus sign
                    latA=float(latAstr) #convert +lon1 to -lon1
                    latAIS=0-latA       #now make it negative
                try:
                    LonAIS=float(dm.lon)
                except ValueError as e:
                    lonAstr= dm.lon     # can't take the float of a negative string
                    lonAstr=lonAstr[1:]  #remove minus sign
                    lonA=float(lonAstr) #convert +lon1 to -lon1
                    lonAIS=0-lonA       #now make it negative
                SpdAIS=float(dm.speed)
                CourseAIS=float(dm.course)
                ShipName="none"
                #print("speed = ", SpdAIS)
                AISv.append(app.map_widget.set_marker(LatAIS, LonAIS,icon=AISvessel_image))   #plot symbol        
                AISList.append(myAIS(dm.mmsi, LatAIS, LonAIS, SpdAIS, CourseAIS, ShipName))
                print(AISList[Alength-1].mmsi)

New contributor

Eddie Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật