You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1_programs_in_files.html
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -285,7 +285,7 @@ <h3><span class="section-number">2.3.2. </span>Other forms of import<a class="he
285
285
between to end points is now accessible as <aclass="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.linspace.html#numpy.linspace" title="(in NumPy v1.19)"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">np.linspace</span></code></a>.</p>
286
286
<p>A second option is to import particular names from a module directly
287
287
into the current namespace. For example, if we planned to use the
288
-
fuctions<aclass="reference external" href="https://docs.python.org/3/library/math.html#math.sin" title="(in Python v3.9)"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">math.sin()</span></code></a> and <aclass="reference external" href="https://docs.python.org/3/library/math.html#math.cos" title="(in Python v3.9)"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">math.cos()</span></code></a> a lot in our script, we
288
+
functions<aclass="reference external" href="https://docs.python.org/3/library/math.html#math.sin" title="(in Python v3.9)"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">math.sin()</span></code></a> and <aclass="reference external" href="https://docs.python.org/3/library/math.html#math.cos" title="(in Python v3.9)"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">math.cos()</span></code></a> a lot in our script, we
the practical details of including tests in your code here.</p>
621
621
<p>There are a number of Python packages which support code testing. The
622
622
concepts are largely similar so rather than get bogged down in the
623
-
details of multiple frameworks, we will introduce <aclass="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v0.1.dev280+gf453460)"><spanclass="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
623
+
details of multiple frameworks, we will introduce <aclass="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v0.1.dev285+ge8504e0)"><spanclass="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
624
624
<divclass="section" id="pytest-tests">
625
625
<h3><spanclass="section-number">2.7.1. </span>Pytest tests<aclass="headerlink" href="#pytest-tests" title="Permalink to this headline">¶</a></h3>
626
626
<p>A Pytest test is simply a function whose name starts with <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">test_</span></code>. In
to use capitals, when underscores and so on. This is covered by PEP 8
278
278
and we reproduce some of the important rules below. The second aspect
279
279
is the choice of the letter, word, or words that make up a name. This
280
-
is much more a matter of judgment, though there are guiding principles
280
+
is much more a matter of judgement, though there are guiding principles
281
281
that greatly help with clarity.</p>
282
282
<divclass="section" id="pep-8-name-conventions">
283
283
<h3><spanclass="section-number">4.4.1. </span>PEP 8 name conventions<aclass="headerlink" href="#pep-8-name-conventions" title="Permalink to this headline">¶</a></h3>
Copy file name to clipboardExpand all lines: 4_abstract_data_types.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -513,7 +513,7 @@ <h3><span class="section-number">5.3.1. </span>Amortised complexity and worst ca
513
513
only occurs when the list has to be extended. How often is that?
514
514
Suppose the list has just been reallocated (at a cost of
515
515
<spanclass="math notranslate nohighlight">\(O(n)\)</span>). The new memory allocation is <spanclass="math notranslate nohighlight">\(kn\)</span> large, but we’ve
516
-
aready used <spanclass="math notranslate nohighlight">\(n\)</span> locations so we get <spanclass="math notranslate nohighlight">\((k-1)n\)</span> more cheap
516
+
already used <spanclass="math notranslate nohighlight">\(n\)</span> locations so we get <spanclass="math notranslate nohighlight">\((k-1)n\)</span> more cheap
517
517
<spanclass="math notranslate nohighlight">\(O(1)\)</span> append operations before we have to reallocate
518
518
again. <spanclass="math notranslate nohighlight">\((k-1)n = O(n)\)</span> so this means that adding <spanclass="math notranslate nohighlight">\(O(n)\)</span>
<p>This shows information about a <aclass="reference internal" href="#term-call-stack"><spanclass="xref std std-term">call stack</span></a> comprising three
309
309
<aclass="reference internal" href="#term-stack-frame"><spanclass="xref std std-term">stack frames</span></a>. Look first at the bottom-most
310
310
frame, which corresponds to the function in which the exception
311
-
occured. The traceback for this frame starts:</p>
311
+
occurred. The traceback for this frame starts:</p>
<spanid="typesafe-fib"></span><divclass="code-block-caption"><spanclass="caption-number">Listing 6.1 </span><spanclass="caption-text">A version of the Fibbonacci function which raises an
366
+
<spanid="typesafe-fib"></span><divclass="code-block-caption"><spanclass="caption-number">Listing 6.1 </span><spanclass="caption-text">A version of the Fibonacci function which raises an
367
367
exception if a non-integer type is passed as the
368
368
argument.</span><aclass="headerlink" href="#id5" title="Permalink to this code">¶</a></div>
between this and the previous errors we have seen is that the bottom
407
407
<aclass="reference internal" href="#term-stack-frame"><spanclass="xref std std-term">stack frame</span></a> explicitly shows the exception being raised, while
408
408
previously the stack showed a piece of code where an error had
409
-
occured. This minor difference has to do with whether the particular
410
-
piece of code where the exception occured is written in Python, or is
409
+
occurred. This minor difference has to do with whether the particular
410
+
piece of code where the exception occurred is written in Python, or is
411
411
written in a language such as C and called from Python. This
412
412
distinction is of negligible importance for our current purposes.</p>
413
413
<divclass="admonition note">
@@ -530,7 +530,7 @@ <h3><span class="section-number">6.5.3. </span>Exception handling and the call s
530
530
point which is ultimately inside several <aclass="reference external" href="https://docs.python.org/3/reference/compound_stmts.html#try" title="(in Python v3.9)"><codeclass="xref std std-keyword docutils literal notranslate"><spanclass="pre">try</span></code></a> blocks.</p>
531
531
<p>The <aclass="reference internal" href="1_programs_in_files.html#term-Python-interpreter"><spanclass="xref std std-term">Python interpreter</span></a> deals with this situation by starting
532
532
from the current <aclass="reference internal" href="#term-stack-frame"><spanclass="xref std std-term">stack frame</span></a> and working upwards, a process
533
-
known as <em>unwinding the stack</em>. In pseudocode, the alogrithm is:</p>
533
+
known as <em>unwinding the stack</em>. In pseudocode, the algorithm is:</p>
@@ -551,9 +551,9 @@ <h2><span class="section-number">6.6. </span>Exceptions are not always errors<a
551
551
concepts. While user errors and bugs in programs typically result in
552
552
an exception being raised, it is not the case that all exceptions
553
553
result from errors. The name “exception” means what it says, it is an
554
-
event whose occurance requires an exception to the normal sequence of
554
+
event whose occurrence requires an exception to the normal sequence of
555
555
execution.</p>
556
-
<p>The <aclass="reference external" href="https://docs.python.org/3/library/exceptions.html#StopIteration" title="(in Python v3.9)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">StopIteration</span></code></a> exception which we encoutered in
556
+
<p>The <aclass="reference external" href="https://docs.python.org/3/library/exceptions.html#StopIteration" title="(in Python v3.9)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">StopIteration</span></code></a> exception which we encountered in
557
557
<aclass="reference internal" href="4_abstract_data_types.html#iterator-protocol"><spanclass="std std-numref">Section 5.5</span></a> is a good example of an <aclass="reference internal" href="#term-exception"><spanclass="xref std std-term">exception</span></a>
558
558
which does not indicate an error. The end of the set of things to be
559
559
iterated over does not indicate that something has gone wrong, but it
0 commit comments