Concise and elegant:
import itertools
class resource_cl():
newid = itertools.count().next
def __init__(self):
self.id = resource_cl.newid()
...
More Related Contents:
- Why does it say that my instance has no attribute x?
- Understanding Python super() with __init__() methods [duplicate]
- Python function overloading
- Saving and loading multiple objects in pickle file?
- How to keep track of class instances?
- Is it possible to make abstract classes in Python?
- Nested classes’ scope?
- What is the __dict__.__dict__ attribute of a Python class?
- What is the `self` parameter in class methods?
- Why do attribute references act like this with Python inheritance? [duplicate]
- Calling functions from a Tkinter Frame to another
- How can I pickle a dynamically created nested class in python?
- Does Python have class prototypes (or forward declarations)?
- How to properly overload the __add__ method?
- What is the purpose of python’s inner classes?
- The scope of names defined in class block doesn’t extend to the methods’ blocks. Why is that?
- Python: How do I make a subclass from a superclass?
- How to implement a binary search tree in Python?
- Getting container/parent object from within python
- What are the parentheses for at the end of Python method names? [duplicate]
- class method generates “TypeError: … got multiple values for keyword argument …”
- Understanding __init_subclass__
- Should I use instance or class attributes if there will only be one instance? [closed]
- How can I choose a custom string representation for a class itself (not instances of the class)?
- Missing 1 required positional argument
- How can I dynamically create class methods for a class in python [duplicate]
- What’s an example use case for a Python classmethod?
- Are functions objects in Python?
- Provide __classcell__ example for Python 3.6 metaclass
- Type Hinting for objects of type that’s being defined [duplicate]