Enjoy the flexibility of structs with esu!
You can create types on the fly with previously declared fields and methods by using esu struct.
The created type additionally contains methods for equation, hashing and string representation.
pip install esufrom esu import Struct
Customer = Struct(
'Customer',
'name', 'age',
methods={
'greeting': lambda self: "Hello {}".format(self.__dict__['name'])
})
dave = Customer()
dave.name = 'Dave'
dave.age = 25
dave.greeting() # => Hello Dave
anna = Customer('Anna', 28)
anna.greeting() # => Hello Annafrom esu import OpenStruct
bob = OpenStruct()
bob.name = Bob
bob.age = 54
print(bob) # => [name=Bob, age=54]
su = OpenStruct({'name': 'Su', 'gender': 'female'})
su.employed = True
print(su) # => [name=Su, gender=female, employed=True]For further information, read the documentation that can be found: https://esu.readthedocs.io
- Fork it!
- Make your changes!
- Send a PR!