Created
October 31, 2013 18:13
-
-
Save f0t0n/7254302 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Employee(object): | |
def __init__(self, first_name, last_name, speciality): | |
self._first_name = first_name | |
self._last_name = last_name | |
self._speciality = speciality | |
class Driver(Employee): | |
pass | |
# Just defaultdict(Employee) will try to return us an instance of class | |
# that will cause TypeError: __init__() takes exactly 4 arguments (1 given) | |
# So we're just returning the class itself. | |
factory = defaultdict(lambda: Employee) | |
for key in ('x', 'y', 'z'): | |
print type(factory[key]('Jimmy', 'Winter', 'engineer')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment