MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / create_init

Method create_init

Solutions/6_4/structure.py:17–27  ·  view source on GitHub ↗

Create an __init__ method from _fields

(cls)

Source from the content-addressed store, hash-verified

15
16 @classmethod
17 def create_init(cls):
18 '''
19 Create an __init__ method from _fields
20 '''
21 args = ','.join(cls._fields)
22 code = f'def __init__(self, {args}):\n'
23 for name in cls._fields:
24 code += f' self.{name} = {name}\n'
25 locs = { }
26 exec(code, locs)
27 cls.__init__ = locs['__init__']

Callers 1

stock.pyFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected