From e40d97c53852415c8c28a0d9c0463f1ee48f3e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= <sornjure@gmail.com> Date: Wed, 27 Feb 2019 17:05:57 +0100 Subject: [PATCH] Attributes --- README.md | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f882626..319f830 100644 --- a/README.md +++ b/README.md @@ -1391,25 +1391,10 @@ Introspection and Metaprograming ### Attributes ```python -class Z: - def __init__(self): - self.a = 'abcde' - self.b = 12345 -``` - -```python ->>> z = Z() - ->>> vars(z) -{'a': 'abcde', 'b': 12345} - ->>> getattr(z, 'a') -'abcde' - ->>> hasattr(z, 'c') -False - ->>> setattr(z, 'c', 10) +<dict> = vars(<object>) +<bool> = hasattr(<object>, '<attr_name>') +value = getattr(<object>, '<attr_name>') +setattr(<object>, '<attr_name>', value) ``` ### Parameters