int
is immutable so you can’t modify it after it is created, use __new__
instead
class TestClass(int):
def __new__(cls, *args, **kwargs):
return super(TestClass, cls).__new__(cls, 5)
print TestClass()
More Related Contents:
- Subclassing tuple with multiple __init__ arguments
- Why aren’t superclass __init__ methods automatically invoked?
- How to create a subclass in python that is inherited from turtle Module
- Understanding Python super() with __init__() methods [duplicate]
- What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__()
- Calling parent class __init__ with multiple inheritance, what’s the right way?
- How to dynamically change base class of instances at runtime?
- Is it possible to make abstract classes in Python?
- Python: avoid new line with print command [duplicate]
- Why do attribute references act like this with Python inheritance? [duplicate]
- TypeError: module.__init__() takes at most 2 arguments (3 given)
- Dynamic inheritance in Python
- Read data from CSV file and transform from string to correct data-type, including a list-of-integer column
- Overriding properties in python
- NameError from Python input() function [duplicate]
- Django model inheritance: create sub-instance of existing instance (downcast)?
- Multiple (asynchronous) connections with urllib2 or other http library?
- Why can’t I subclass datetime.date?
- What does from __future__ import absolute_import actually do?
- In Python, how do I indicate I’m overriding a method?
- Relative imports in python 2.5
- Is it possible to make abstract classes?
- Understanding __init_subclass__
- Python: Inherit the superclass __init__
- How to subclass Python list without type problems?
- Calling superclass constructors in python with different arguments
- Force child class to override parent’s methods
- The inheritance of attributes using __init__
- How to remove a field from the parent Form in a subclass?
- Accessing attribute from parent class inside child class