puffadder
A boiler plate reducing library for Python, inspired by Project Lombok for Java.
@to_string
Adds a str function to the class that returns all public class attributes in a neatly formatted string.
Puffadder | Vanilla Python |
@to_string
class Student(object):
_private_attribute = "This will not be seen"
name = "Sally"
age = 22
full_time = True
>>> john = Student()
>>> john.name = "John"
>>> print(Student())
{name=John, age=22, full_time=True}
|
class Student(object):
_private_attribute = "This will not be seen"
name = "Sally"
age = 22
full_time = True
def __str__(self):
return "{{name={}, age={}, full_time={}}}"
.format(self.name, self.age, self.ful_time)
>>> john = Student()
>>> john.name = "John"
>>> print(Student())
{name=John, age=22, full_time=True}
|
@builder
Adds a constructor to the class that sets all public class attributes in the constructor. If a constructor was defined it is run after the generated constructor.
Puffadder | Vanilla Python |
@builder
class Student(object):
_private_attribute = "This will not be seen"
name = "Sally"
age = 22
full_time = True
john = Student(
name="John",
age=30,
full_time=False
)
|
class Student(object):
def __init__(self, name="Sally", age=22, full_time=True):
self.name = name
self.age = age
self.full_time = full_time
self._private_attribute = "This will not be seen"
john = Student(
name="John",
age=30,
full_time=False
)
|