inheritance - Python : Wrapper class and constructor parameters -


i create simple wrapper class frozenset changes constructor arguments. here have come (as in java) :

class edge(frozenset):     def __init__(self, a, b):         frozenset.__init__(self, {a, b}) 

i have edge(0,1) createfrozenset({0,1}).

however, error:

>>>edge(0,1) typeerror: edge expected @ 1 arguments, got 2 

frozenset immutable, you'll need override __new__ method:

class edge(frozenset):     def __new__(cls, a, b):         return super(edge, cls).__new__(cls, {a, b}) 

see here.


Popular posts from this blog

html/hta mutiple file in audio player -

debugging - Reference - What does this error mean in PHP? -