|
2184 | 2184 | <span class="hljs-keyword">return</span> template(<span class="hljs-string">'<h1>{{title}}</h1>'</span>, title=sport)
|
2185 | 2185 | </code></pre></div>
|
2186 | 2186 |
|
2187 |
| -<div><h3 id="restrequest">REST Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@post('/odds/<sport>')</span> |
| 2187 | +<div><h3 id="restrequest">REST Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@post('/<sport>/odds')</span> |
2188 | 2188 | <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">odds_handler</span><span class="hljs-params">(sport)</span>:</span>
|
2189 | 2189 | team = request.forms.get(<span class="hljs-string">'team'</span>)
|
2190 | 2190 | home_odds, away_odds = <span class="hljs-number">2.44</span>, <span class="hljs-number">3.29</span>
|
|
2196 | 2196 | <div><h4 id="test">Test:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install requests</span>
|
2197 | 2197 | <span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> threading, requests
|
2198 | 2198 | <span class="hljs-meta">>>> </span>threading.Thread(target=run, daemon=<span class="hljs-keyword">True</span>).start()
|
2199 |
| -<span class="hljs-meta">>>> </span>url = <span class="hljs-string">'http://localhost:8080/odds/football'</span> |
| 2199 | +<span class="hljs-meta">>>> </span>url = <span class="hljs-string">'http://localhost:8080/football/odds'</span> |
2200 | 2200 | <span class="hljs-meta">>>> </span>data = {<span class="hljs-string">'team'</span>: <span class="hljs-string">'arsenal f.c.'</span>}
|
2201 | 2201 | <span class="hljs-meta">>>> </span>response = requests.post(url, data=data)
|
2202 | 2202 | <span class="hljs-meta">>>> </span>response.json()
|
|
2246 | 2246 | 3 38.012 MiB 0.344 MiB a = [*range(10000)]
|
2247 | 2247 | 4 38.477 MiB 0.465 MiB b = {*range(10000)}
|
2248 | 2248 | </code></pre>
|
2249 |
| -<div><h3 id="callgraph">Call Graph</h3><div><h4 id="generatesapngimageofacallgraphwithhighlightedbottlenecks">Generates a PNG image of a call graph with highlighted bottlenecks:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install pycallgraph</span> |
2250 |
| -<span class="hljs-keyword">from</span> pycallgraph <span class="hljs-keyword">import</span> output, PyCallGraph |
| 2249 | +<div><h3 id="callgraph">Call Graph</h3><div><h4 id="generatesapngimageofacallgraphwithhighlightedbottlenecks">Generates a PNG image of a call graph with highlighted bottlenecks:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install pycallgraph2</span> |
| 2250 | +<span class="hljs-keyword">from</span> pycallgraph2 <span class="hljs-keyword">import</span> output, PyCallGraph |
2251 | 2251 | <span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime
|
2252 |
| -time_str = datetime.now().strftime(<span class="hljs-string">'%Y%m%d%H%M%S'</span>) |
2253 |
| -filename = <span class="hljs-string">f'profile-<span class="hljs-subst">{time_str}</span>.png'</span> |
| 2252 | +filename = <span class="hljs-string">f'profile-<span class="hljs-subst">{datetime.now():%Y%m%d%H%M%S}</span>.png'</span> |
2254 | 2253 | drawer = output.GraphvizOutput(output_file=filename)
|
2255 | 2254 | <span class="hljs-keyword">with</span> PyCallGraph(drawer):
|
2256 | 2255 | <code_to_be_profiled>
|
|
2547 | 2546 | <Surf>.set_at((x, y), color) <span class="hljs-comment"># Updates pixel.</span>
|
2548 | 2547 | <Surf>.blit(<Surf>, (x, y)) <span class="hljs-comment"># Draws passed surface to the surface.</span>
|
2549 | 2548 | </code></pre>
|
2550 |
| -<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pygame.transform <span class="hljs-keyword">import</span> scale, … |
| 2549 | +<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pygame.transform <span class="hljs-keyword">import</span> scale, ... |
2551 | 2550 | <Surf> = scale(<Surf>, (width, height)) <span class="hljs-comment"># Returns scaled surface.</span>
|
2552 | 2551 | <Surf> = rotate(<Surf>, degrees) <span class="hljs-comment"># Returns rotated and scaled surface.</span>
|
2553 | 2552 | <Surf> = flip(<Surf>, x_bool, y_bool) <span class="hljs-comment"># Returns flipped surface.</span>
|
2554 | 2553 | </code></pre>
|
2555 |
| -<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pygame.draw <span class="hljs-keyword">import</span> line, … |
| 2554 | +<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pygame.draw <span class="hljs-keyword">import</span> line, ... |
2556 | 2555 | line(<Surf>, color, (x1, y1), (x2, y2), width) <span class="hljs-comment"># Draws a line to the surface.</span>
|
2557 | 2556 | arc(<Surf>, color, <Rect>, from_rad, to_rad) <span class="hljs-comment"># Also: ellipse(<Surf>, color, <Rect>)</span>
|
2558 | 2557 | rect(<Surf>, color, <Rect>) <span class="hljs-comment"># Also: polygon(<Surf>, color, points)</span>
|
|
0 commit comments