Use the factory function:
def GetTorrentClass(slots_iterable): class Torrent(object): __slots__ = slots_iterable return Torrent
Please note that to use the slots:
slots_iterable should be iterable from strings- Your class should be in a new style.
- Your class cannot inherit a class that implements
__dict__ (i.e. not just __slots__ )
Now you say that you do not need to change the structure of the object, using __slots__ not the only (and probably not the best) solution to your problem: using slots makes your class more difficult to use in code.
Instead, you can do the following:
class Torrent(object): def __init__(self, fields): self.fields = fields
This way you are sure that only your actual fields will be stored in your db.
source share