Python: deleting/removing class instances with none unique names -


for bit of context, looking create class called peasant game making in python. these workers have many attributes. created name , given id. since names have chance not unique id called delete class. think going instantiation wrong should id creating them unigue id giving them name?

class peasant:     peasantcount = 0      def __init__(self, name):         ...         peasant.id += 1         self.id = peasant.id         peasant.peasantcount += 1      def died(self, hp):         if hp <= 0:         peasant.peasantcount -=1         del self 

the def died method kill peasants if can make work, instance not deleted when instance.died(0) called.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -