I'm trying to implement super()
per this SO answer.
I have the following class:
class Collection():
"""returns a collection curser from mongodb"""
def __init__(self, db, collection_name):
self.db = db
self.collection_name = collection_name
if not hasattr(self.__class__, 'client'):
self.__class__.client = MongoClient()
self.data_base = getattr(self.client, self.db)
self.collection = getattr(self.data_base, self.collection_name)
and the following subclass:
class User(Collection):
def __init__(self, db, collection_name):
super(User, self).__init__(db, collection_name)
Calling the Collection
class works fine:
agents = Collection('hkpr_restore','agents')
Calling the subclass:
user = User('hkpr_restore','agents')
I get an error:
Traceback (most recent call last):
File "main.py", line 37, in <module>
user = User('hkpr_restore','agents')
File "filepath/user.py", line 35, in __init__
super(User, self).__init__(db, collection_name)
TypeError: must be type, not classobj
What am I doing wrong?