Browse Source

Metaprogramming

pull/3/head
Jure Šorn 7 years ago
parent
commit
6d07fa301a
1 changed files with 5 additions and 17 deletions
  1. 22
      README.md

22
README.md

@ -630,31 +630,19 @@ Introspection and Metaprograming
```python ```python
>>> class B: >>> class B:
... def __init__(self): ... def __init__(self):
... self.a= 'sdfsd'
... self.b = 123324
... self.a = 'abcde'
... self.b = 12345
>>> b = B() >>> b = B()
``` ```
### Getattr
### Getattr, Hasattr, Setattr
```python ```python
>>> getattr(b, 'a')
'sdfsd'
```
#### Is the same as:
>>> getattr(b, 'a') # Same as B.__getattribute__(b, 'a')
'abcde'
```python
B.__getattribute__(b, 'a')
```
### Hasattr
```python
>>> hasattr(b, 'c') >>> hasattr(b, 'c')
False False
```
### Setattr
```python
>>> setattr(b, 'c', 10) >>> setattr(b, 'c', 10)
``` ```

Loading…
Cancel
Save