Dev HelpersOpen library
← Back

Construct with a classmethod

Construct with a classmethod. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

class User:
    def __init__(self, name):
        self.name = name
    @classmethod
    def from_record(cls, record):
        return cls(record['name'])
print(User.from_record({'name':'Ada'}).name)

Sample output

Ada