python Programming Glossary: self.type
Use a method both from a class and from an instance http://stackoverflow.com/questions/10413488/use-a-method-both-from-a-class-and-from-an-instance __init__ self func obj type self.func func self.obj obj self.type type def __call__ self args kw assert 'self' not in kw and 'cls'.. to a classinstancemethod return self.func self.obj self.type args kw def __repr__ self if self.obj is None return ' bound.. if self.obj is None return ' bound class method s. s ' self.type.__name__ self.func.func_name else return ' bound method s. s..
Simple regex-based lexer in Python http://stackoverflow.com/questions/133886/simple-regex-based-lexer-in-python type value and position. def __init__ self type val pos self.type type self.val val self.pos pos def __str__ self return ' s s.. val self.pos pos def __str__ self return ' s s at s' self.type self.val self.pos class LexerError Exception Lexer error exception...
Making a multi-table inheritance design generic in Django http://stackoverflow.com/questions/1712683/making-a-multi-table-inheritance-design-generic-in-django def save self force_insert False force_update False if self.type_id is None self.type ContentType.objects.get_for_model self.__class__.. False force_update False if self.type_id is None self.type ContentType.objects.get_for_model self.__class__ super BaseModel.. force_insert force_update def get_instance self return self.type.get_object_for_this_type id self.id share improve this answer..
How can I pickle a nested class in python? http://stackoverflow.com/questions/1947904/how-can-i-pickle-a-nested-class-in-python it like this class ObjectToPickle object def __init__ self self.type WidgetType.TextType Trying to serialize an instance of the ObjectToPickle..
Overriding append method after inheriting from a Python List http://stackoverflow.com/questions/3487434/overriding-append-method-after-inheriting-from-a-python-list method like so class TypedList list def __init__ self type self.type type def append item if not isinstance item type raise TypeError.. name . class TypedList list def __init__ self type self.type type def append self item if not isinstance item self.type raise.. self.type type def append self item if not isinstance item self.type raise TypeError 'item is not of type s' self.type super TypedList..
django model polymorphism with proxy inheritance http://stackoverflow.com/questions/7526088/django-model-polymorphism-with-proxy-inheritance self return self.name def __init__ self args kwargs if self.type self.__class__ getattr sys.modules __name__ self.type 'Discount'.. if self.type self.__class__ getattr sys.modules __name__ self.type 'Discount' super Discount self .__init__ args kwargs class ValueDiscount.. args kwargs super Discount self .__init__ args kwargs if self.type self.__class__ getattr sys.modules __name__ self.type 'Discount'..
|