Hello folks; My name is Jürgen an I am new here.
I have a problem with playing with some class function although I have read some books and were watching some tutorials, however, my simple code is not working proberly.
I have greated a class where I want to collect each object in a list in order to print all objects if needed later on. On the other hand I created a del method to remove objects if needed. I found out that the del method isn’t working as long as the append function is in use. I also struggled to dereference the list in C the * operator is in use therefore.
Do you have any suggestions on this?
Here you can see my code:
class grocery:
count=0
liste=[]
def __init__(self):
print('Grocery created')
#grocery.liste.append(self)
grocery.count +=1
def __del__(self):
# grocery.liste.remove(self)
print('Objekt gelöscht')
grocery.count -=1
## creation
obj1= grocery()
obj2= grocery()
obj3= grocery()
obj4= grocery()
obj5= grocery()
##printing
print(grocery.count)
print(len(grocery.liste))
"""deleting"""
del obj1
print(grocery.count)
As you can see I have comment out the hamper thing. Do you have also a recommendation of a good book ?
Thank you Jürgen