From 6d07fa301a40247406015f21fdf483bbcf1cc4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 18 Apr 2018 02:31:16 +0200 Subject: [PATCH] Metaprogramming --- README.md | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e9f553e..e799e4a 100644 --- a/README.md +++ b/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) ```