mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
typos [thanks G.P.]
This commit is contained in:
@@ -625,6 +625,7 @@ ImportError: No module named constants</samp></pre>
|
||||
<pre><code>from . import constants
|
||||
import sys</code></pre>
|
||||
<p>There are variations of this problem scattered throughout the <code>chardet</code> library. In some places it’s “<code>import constants, sys</code>”; in other places, it’s “<code>import constants, re</code>”. The fix is the same: manually split the import statement into two lines, one for the relative import, the other for the absolute import.
|
||||
<p>FIXME-xref to as-yet-unwritten PEP 8 style section (which says you should put all imports on their own line)
|
||||
<p>Onward!
|
||||
<h3 id=namefileisnotdefined>Name <var>'file'</var> is not defined</h3>
|
||||
<aside>open() is the new file(). PapayaWhip is the new black.</aside>
|
||||
|
||||
@@ -44,7 +44,7 @@ td a:link, td a:visited{border:0}
|
||||
<th>And Python Calls…
|
||||
<tr><th>①
|
||||
<td>to initialize an instance
|
||||
<td><code>x = MyCustomClass()</code>
|
||||
<td><code>x = MyClass()</code>
|
||||
<td><code>x.__init__()</code>
|
||||
<tr><th>②
|
||||
<td>the “official” representation as a string
|
||||
@@ -108,11 +108,11 @@ td a:link, td a:visited{border:0}
|
||||
<th>You Want…
|
||||
<th>So You Write…
|
||||
<th>And Python Calls…
|
||||
<tr><th>②
|
||||
<tr><th>①
|
||||
<td>to get a computed attribute (unconditionally)
|
||||
<td><code>x.my_property</code>
|
||||
<td><a href=http://www.python.org/doc/3.0/reference/datamodel.html#object.__getattribute__><code>x.__getattribute__(<var>"my_property"</var>)</code></a>
|
||||
<tr><th>①
|
||||
<tr><th>②
|
||||
<td>to get a computed attribute (fallback)
|
||||
<td><code>x.my_property</code>
|
||||
<td><a href=http://www.python.org/doc/3.0/reference/datamodel.html#object.__getattr__><code>x.__getattr__(<var>"my_property"</var>)</code></a>
|
||||
@@ -214,7 +214,7 @@ AttributeError</samp></pre>
|
||||
<th>You Want…
|
||||
<th>So You Write…
|
||||
<th>And Python Calls…
|
||||
<tr><th>①
|
||||
<tr><th>
|
||||
<td>to “call” an instance like a function
|
||||
<td><code>my_instance()</code>
|
||||
<td><a href=http://www.python.org/doc/3.0/reference/datamodel.html#object.__call__><code>my_instance.__call__()</code></a>
|
||||
@@ -738,6 +738,8 @@ class FieldStorage:
|
||||
|
||||
<p>This is how the [FIXME-xref] <code>with <var>file</var></code> idiom works.
|
||||
|
||||
<p>FIXME-xref to as-yet-unwritten section on function annotations
|
||||
|
||||
<pre><code># excerpt from io.py:
|
||||
def _checkClosed(self, msg=None):
|
||||
"""Internal: raise an ValueError if file is closed
|
||||
|
||||
@@ -34,8 +34,6 @@ ul li ol{margin:0;padding:0 0 0 2.5em}
|
||||
<li><a href=your-first-python-program.html#readability>Writing readable code</a>
|
||||
<ol>
|
||||
<li><a href=your-first-python-program.html#docstrings>Docstrings</a>
|
||||
<li><a href=your-first-python-program.html#functionannotations>Function annotations</a>
|
||||
<li><a href=your-first-python-program.html#styleconventions>Style conventions</a>
|
||||
</ol>
|
||||
<li><a href=your-first-python-program.html#everythingisanobject>Everything is an object</a>
|
||||
<ol>
|
||||
@@ -393,6 +391,8 @@ ul li ol{margin:0;padding:0 0 0 2.5em}
|
||||
<li>Set comprehensions
|
||||
<li>Dictionary comprehensions
|
||||
<li>Views (several dictionary methods return them, they're dynamic, update when the dictionary changes, etc.)
|
||||
<li>Function annotations
|
||||
<li>PEP 8 style conventions
|
||||
<li>Importing modules
|
||||
<ol>
|
||||
<li>...mention why from module import * is only allowed at module level
|
||||
|
||||
Reference in New Issue
Block a user