Browse Source

Metaprogramming

pull/3/head
Jure Šorn 6 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
>>> class B:
... def __init__(self):
... self.a= 'sdfsd'
... self.b = 123324
... self.a = 'abcde'
... self.b = 12345
>>> b = B()
```
### Getattr
### Getattr, Hasattr, Setattr
```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')
False
```
### Setattr
```python
>>> setattr(b, 'c', 10)
```

Loading…
Cancel
Save