4 kyu

Lazy Init

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:

CreatedSep 12, 2017
PublishedSep 12, 2017
Warriors Trained1915
Total Skips614
Total Code Submissions1220
Total Times Completed359
Python Completions359
Total Stars101
% of votes with a positive feedback rating98% of 96
Total "Very Satisfied" Votes92
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • simosini Avatar
  • Blind4Basics Avatar
Ad