[Tutor] Counting objects: method vs. staticmethod vs. classmethod

Mats Wichmann mats at wichmann.us
Mon Jun 22 15:09:28 EDT 2020


On 6/21/20 8:35 PM, boB Stepp wrote:
> What I want to do:  Every time I instantiate an object of a particular
> class I wish to generate a unique id dependent on a particular
> attribute value and the current number of objects created with that
> attribute value.  Playing around tonight I have come up with the same
> technique expressed slightly differently.  Which is best for what I
> want to do?  Is there a better way to do what I want to do?
> 
> 3.7.5:  import random
> 3.7.5:  from collections import Counter

by the way - bravo for using this "advanced" feature!  :)




More information about the Tutor mailing list