I noticed I often write the following:
class X:
def __init__(self, var1, var2, var3):
self.var1 = var1
self.var2 = var2
self.var3 = var3
# more code here
Is it a good idea to make a template that I can reuse instead of doing this every time? If so, how should I do that?
I wouldn’t suggest using such templates in production code, because
For throw-away prototypes it might be acceptable. Here is an example from the python recipes:
It defines a decorator with can be attached to
__init__:A test: