Browse Source

Introspection

pull/57/head
Jure Šorn 4 years ago
parent
commit
e2b2d7093c
2 changed files with 2 additions and 2 deletions
  1. 2
      README.md
  2. 2
      index.html

2
README.md

@ -2148,7 +2148,7 @@ Introspection
```
```python
<bool> = hasattr(<object>, '<attr_name>') # Checks if getattr raises an error.
<bool> = hasattr(<object>, '<attr_name>') # Checks if getattr() raises an error.
value = getattr(<object>, '<attr_name>') # Raises AttributeError if attribute is missing.
setattr(<object>, '<attr_name>', value) # Only works on user-defined classes.
delattr(<object>, '<attr_name>') # Equivalent to `del <object>.<attr_name>`.

2
index.html

@ -1880,7 +1880,7 @@ last_el = op.methodcaller(<span class="hljs-string">'pop'</span>)(&lt;l
&lt;dict&gt; = vars(&lt;object&gt;) <span class="hljs-comment"># Dict of object's fields. Also &lt;obj&gt;.__dict__.</span>
</code></pre></div>
<pre><code class="python language-python hljs">&lt;bool&gt; = hasattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Checks if getattr raises an error.</span>
<pre><code class="python language-python hljs">&lt;bool&gt; = hasattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Checks if getattr() raises an error.</span>
value = getattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Raises AttributeError if attribute is missing.</span>
setattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>, value) <span class="hljs-comment"># Only works on user-defined classes.</span>
delattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Equivalent to `del &lt;object&gt;.&lt;attr_name&gt;`.</span>

Loading…
Cancel
Save