4 kyu
Lazy Init
359simosini
Description:
How many times we create a python class and in the init method we just write:
self.name1 = name1
self.name2 = name2
.....
for all arguments.....
How boring!!!!
Your task here is to implement a metaclass that let this instantiation be done automatically. But let's see an example:
class Person(metaclass=LazyInit):
def __init__(self, name, age): pass
When we create a Person object like:
a_person = Person('John', 25)
The expected behavior will be:
print(a_person.name) # this will print John
print(a_person.age) # this will print 25
Obviously the number of arguments might be different from class to class.
Don't worry about **kwargs you will never be given keyword arguments in this kata!!!
A little hint: a decorator could help you out doing the job!!!
Good luck lazy folks.....
Metaprogramming
Similar Kata:
Stats:
Created | Sep 12, 2017 |
Published | Sep 12, 2017 |
Warriors Trained | 1915 |
Total Skips | 614 |
Total Code Submissions | 1220 |
Total Times Completed | 359 |
Python Completions | 359 |
Total Stars | 101 |
% of votes with a positive feedback rating | 98% of 96 |
Total "Very Satisfied" Votes | 92 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 6 kyu |