An instance method decorator that also works as a classmethod.
Project description
#Dynamic class and instance methods!
This simple module creates a class method that will also work as an instance method.
```python
import dynamicmethod
class Example(object):
x = 1 # Default classmethod value
def __init__(self, x=0):
self.x = x
@dynamicmethod
def get_x(self):
return self.x
print(Example.get_x())
ex = Example()
print(ex.get_x())
ex.x = 5
print(ex.get_x())
```
This simple module creates a class method that will also work as an instance method.
```python
import dynamicmethod
class Example(object):
x = 1 # Default classmethod value
def __init__(self, x=0):
self.x = x
@dynamicmethod
def get_x(self):
return self.x
print(Example.get_x())
ex = Example()
print(ex.get_x())
ex.x = 5
print(ex.get_x())
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dynamicmethod-1.0.3.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for dynamicmethod-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a9f97420ce856e7c041731b721176362b25099f34a526751a143a40b8200367 |
|
MD5 | 4d7d0b33d6289584c4c3a8319a224778 |
|
BLAKE2b-256 | ca1bd75aa44a2d59effef339f4da442a2eedc9f07663b598b34d5622f2f46ca9 |