Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06bc3ec

Browse files
committed
Format, Command line argumetns, Open, Web, Image
1 parent 9639250 commit 06bc3ec

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ Format
412412
{<el>:.<10} # '<el>......'
413413
{<el>:0} # '<el>'
414414
```
415-
* **Objects are rendered using `'format(<el>, <options>)'`.**
415+
* **Objects are rendered using `'format(<el>, "<options>")'`.**
416416
* **Options can be generated dynamically: `f'{<el>:{<str/int>}[…]}'`.**
417417
* **Adding `'='` to the expression prepends it to the output: `f'{1+1=}'` returns `'1+1=2'`.**
418418
* **Adding `'!r'` to the expression converts object to string by calling its [repr()](#class) method.**
@@ -1550,8 +1550,8 @@ p.add_argument('-<short_name>', '--<name>', type=<type>) # Option (defa
15501550
p.add_argument('<name>', type=<type>, nargs=1) # Mandatory first argument.
15511551
p.add_argument('<name>', type=<type>, nargs='+') # Mandatory remaining args.
15521552
p.add_argument('<name>', type=<type>, nargs='?/*') # Optional argument/s.
1553-
<args> = p.parse_args() # Exits on parsing error.
1554-
<obj> = <args>.<name> # Returns `<type>(<arg>)`.
1553+
args = p.parse_args() # Exits on parsing error.
1554+
<obj> = args.<name> # Returns `<type>(<arg>)`.
15551555
```
15561556

15571557
* **Use `'help=<str>'` to set argument description that will be displayed in help message.**
@@ -1591,7 +1591,7 @@ Open
15911591
<file>.seek(0) # Moves to the start of the file.
15921592
<file>.seek(offset) # Moves 'offset' chars/bytes from the start.
15931593
<file>.seek(0, 2) # Moves to the end of the file.
1594-
<bin_file>.seek(±offset, <anchor>) # Anchor: 0 start, 1 current position, 2 end.
1594+
<bin_file>.seek(±offset, origin) # Origin: 0 start, 1 current position, 2 end.
15951595
```
15961596

15971597
```python
@@ -2568,7 +2568,7 @@ def serve_html(sport):
25682568
return flask.render_template_string('<h1>{{title}}</h1>', title=sport)
25692569
```
25702570
* **Use `'render_template(filename, <kwargs>)'` to render file located in templates dir.**
2571-
* **To return an error code use `'abort(<int>)'` and to redirect use `'redirect(<url>)'`.**
2571+
* **To return an error code use `'abort(<int>)'` and to redirect use `'redirect("<url>")'`.**
25722572
* **`'request.args[<str>]'` returns parameter from the query string (URL part after '?').**
25732573
* **`'session[<str>] = <obj>'` stores session data. Needs `'app.secret_key = <str>'`.**
25742574

@@ -2771,22 +2771,22 @@ from PIL import Image
27712771
```python
27722772
<Image> = Image.new('<mode>', (width, height)) # Creates new image. Also `color=<int/tuple>`.
27732773
<Image> = Image.open(<path>) # Identifies format based on file's contents.
2774-
<Image> = <Image>.convert('<mode>') # Converts image to the new mode.
2774+
<Image> = <Image>.convert('<mode>') # Converts image to the new mode (see Modes).
27752775
<Image>.save(<path>) # Selects format based on extension (PNG/JPG…).
27762776
<Image>.show() # Opens image in the default preview app.
27772777
```
27782778

27792779
```python
2780-
<int/tuple> = <Image>.getpixel((x, y)) # Returns pixel's value (its color).
2781-
<Image>.putpixel((x, y), <int/tuple>) # Updates pixel's value.
2782-
<ImagingCore> = <Image>.getdata() # Returns a flattened view of pixel values.
2783-
<Image>.putdata(<list/ImagingCore>) # Updates pixels with a copy of the sequence.
2780+
<int/tup> = <Image>.getpixel((x, y)) # Returns pixel's value (its color).
2781+
<ImgCore> = <Image>.getdata() # Returns a flattened view of pixel values.
2782+
<Image>.putpixel((x, y), <int/tuple>) # Updates pixel's value. Clips passed int/s.
2783+
<Image>.putdata(<list/ImgCore>) # Updates pixels with a copy of the sequence.
27842784
<Image>.paste(<Image>, (x, y)) # Draws passed image at the specified location.
27852785
```
27862786

27872787
```python
2788-
<Image> = <Image>.filter(<Filter>) # `<Filter> = ImageFilter.<name>(<args>)`
2789-
<Image> = <Enhance>.enhance(<float>) # `<Enhance> = ImageEnhance.<name>(<Image>)`
2788+
<Image> = <Image>.filter(<Filter>) # Use ImageFilter.<name>(<args>) for Filter.
2789+
<Image> = <Enhance>.enhance(<float>) # Use ImageEnhance.<name>(<Image>) for Enhance.
27902790
```
27912791

27922792
```python
@@ -2797,7 +2797,7 @@ from PIL import Image
27972797
### Modes
27982798
* **`'L'` - Lightness (greyscale image). Each pixel is an int between 0 and 255.**
27992799
* **`'RGB'` - Red, green, blue (true color image). Each pixel is a tuple of three ints.**
2800-
* **`'RGBA'` - RGB with alpha. Low alpha (i.e. forth int) makes pixel more transparent.**
2800+
* **`'RGBA'` - RGB with alpha. Low alpha (i.e. forth int) makes pixels more transparent.**
28012801
* **`'HSV'` - Hue, saturation, value. Three ints representing color in HSV color space.**
28022802

28032803

index.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<body>
5656
<header>
57-
<aside>September 27, 2024</aside>
57+
<aside>October 2, 2024</aside>
5858
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
5959
</header>
6060

@@ -380,7 +380,7 @@
380380
</code></pre></div>
381381

382382
<ul>
383-
<li><strong>Objects are rendered using <code class="python hljs"><span class="hljs-string">'format(&lt;el&gt;, &lt;options&gt;)'</span></code>.</strong></li>
383+
<li><strong>Objects are rendered using <code class="python hljs"><span class="hljs-string">'format(&lt;el&gt;, "&lt;options&gt;")'</span></code>.</strong></li>
384384
<li><strong>Options can be generated dynamically: <code class="python hljs"><span class="hljs-string">f'<span class="hljs-subst">{&lt;el&gt;:{&lt;str/int&gt;}</span>[…]}'</span></code>.</strong></li>
385385
<li><strong>Adding <code class="python hljs"><span class="hljs-string">'='</span></code> to the expression prepends it to the output: <code class="python hljs"><span class="hljs-string">f'<span class="hljs-subst">{<span class="hljs-number">1</span>+<span class="hljs-number">1</span>=}</span>'</span></code> returns <code class="python hljs"><span class="hljs-string">'1+1=2'</span></code>.</strong></li>
386386
<li><strong>Adding <code class="python hljs"><span class="hljs-string">'!r'</span></code> to the expression converts object to string by calling its <a href="#class">repr()</a> method.</strong></li>
@@ -1314,8 +1314,8 @@
13141314
p.add_argument(<span class="hljs-string">'&lt;name&gt;'</span>, type=&lt;type&gt;, nargs=<span class="hljs-number">1</span>) <span class="hljs-comment"># Mandatory first argument.</span>
13151315
p.add_argument(<span class="hljs-string">'&lt;name&gt;'</span>, type=&lt;type&gt;, nargs=<span class="hljs-string">'+'</span>) <span class="hljs-comment"># Mandatory remaining args.</span>
13161316
p.add_argument(<span class="hljs-string">'&lt;name&gt;'</span>, type=&lt;type&gt;, nargs=<span class="hljs-string">'?/*'</span>) <span class="hljs-comment"># Optional argument/s.</span>
1317-
&lt;args&gt; = p.parse_args() <span class="hljs-comment"># Exits on parsing error.</span>
1318-
&lt;obj&gt; = &lt;args&gt;.&lt;name&gt; <span class="hljs-comment"># Returns `&lt;type&gt;(&lt;arg&gt;)`.</span>
1317+
args = p.parse_args() <span class="hljs-comment"># Exits on parsing error.</span>
1318+
&lt;obj&gt; = args.&lt;name&gt; <span class="hljs-comment"># Returns `&lt;type&gt;(&lt;arg&gt;)`.</span>
13191319
</code></pre></div>
13201320

13211321
<ul>
@@ -1349,7 +1349,7 @@
13491349
</ul><div><h3 id="fileobject">File Object</h3><pre><code class="python language-python hljs">&lt;file&gt;.seek(<span class="hljs-number">0</span>) <span class="hljs-comment"># Moves to the start of the file.</span>
13501350
&lt;file&gt;.seek(offset) <span class="hljs-comment"># Moves 'offset' chars/bytes from the start.</span>
13511351
&lt;file&gt;.seek(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Moves to the end of the file.</span>
1352-
&lt;bin_file&gt;.seek(±offset, &lt;anchor&gt;) <span class="hljs-comment"># Anchor: 0 start, 1 current position, 2 end.</span>
1352+
&lt;bin_file&gt;.seek(±offset, origin) <span class="hljs-comment"># Origin: 0 start, 1 current position, 2 end.</span>
13531353
</code></pre></div></div></div>
13541354

13551355

@@ -2108,7 +2108,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
21082108

21092109
<ul>
21102110
<li><strong>Use <code class="python hljs"><span class="hljs-string">'render_template(filename, &lt;kwargs&gt;)'</span></code> to render file located in templates dir.</strong></li>
2111-
<li><strong>To return an error code use <code class="python hljs"><span class="hljs-string">'abort(&lt;int&gt;)'</span></code> and to redirect use <code class="python hljs"><span class="hljs-string">'redirect(&lt;url&gt;)'</span></code>.</strong></li>
2111+
<li><strong>To return an error code use <code class="python hljs"><span class="hljs-string">'abort(&lt;int&gt;)'</span></code> and to redirect use <code class="python hljs"><span class="hljs-string">'redirect("&lt;url&gt;")'</span></code>.</strong></li>
21122112
<li><strong><code class="python hljs"><span class="hljs-string">'request.args[&lt;str&gt;]'</span></code> returns parameter from the query string (URL part after '?').</strong></li>
21132113
<li><strong><code class="python hljs"><span class="hljs-string">'session[&lt;str&gt;] = &lt;obj&gt;'</span></code> stores session data. Needs <code class="python hljs"><span class="hljs-string">'app.secret_key = &lt;str&gt;'</span></code>.</strong></li>
21142114
</ul>
@@ -2264,26 +2264,26 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
22642264

22652265
<pre><code class="python language-python hljs">&lt;Image&gt; = Image.new(<span class="hljs-string">'&lt;mode&gt;'</span>, (width, height)) <span class="hljs-comment"># Creates new image. Also `color=&lt;int/tuple&gt;`.</span>
22662266
&lt;Image&gt; = Image.open(&lt;path&gt;) <span class="hljs-comment"># Identifies format based on file's contents.</span>
2267-
&lt;Image&gt; = &lt;Image&gt;.convert(<span class="hljs-string">'&lt;mode&gt;'</span>) <span class="hljs-comment"># Converts image to the new mode.</span>
2267+
&lt;Image&gt; = &lt;Image&gt;.convert(<span class="hljs-string">'&lt;mode&gt;'</span>) <span class="hljs-comment"># Converts image to the new mode (see Modes).</span>
22682268
&lt;Image&gt;.save(&lt;path&gt;) <span class="hljs-comment"># Selects format based on extension (PNG/JPG…).</span>
22692269
&lt;Image&gt;.show() <span class="hljs-comment"># Opens image in the default preview app.</span>
22702270
</code></pre>
2271-
<pre><code class="python language-python hljs">&lt;int/tuple&gt; = &lt;Image&gt;.getpixel((x, y)) <span class="hljs-comment"># Returns pixel's value (its color).</span>
2272-
&lt;Image&gt;.putpixel((x, y), &lt;int/tuple&gt;) <span class="hljs-comment"># Updates pixel's value.</span>
2273-
&lt;ImagingCore&gt; = &lt;Image&gt;.getdata() <span class="hljs-comment"># Returns a flattened view of pixel values.</span>
2274-
&lt;Image&gt;.putdata(&lt;list/ImagingCore&gt;) <span class="hljs-comment"># Updates pixels with a copy of the sequence.</span>
2271+
<pre><code class="python language-python hljs">&lt;int/tup&gt; = &lt;Image&gt;.getpixel((x, y)) <span class="hljs-comment"># Returns pixel's value (its color).</span>
2272+
&lt;ImgCore&gt; = &lt;Image&gt;.getdata() <span class="hljs-comment"># Returns a flattened view of pixel values.</span>
2273+
&lt;Image&gt;.putpixel((x, y), &lt;int/tuple&gt;) <span class="hljs-comment"># Updates pixel's value. Clips passed int/s.</span>
2274+
&lt;Image&gt;.putdata(&lt;list/ImgCore&gt;) <span class="hljs-comment"># Updates pixels with a copy of the sequence.</span>
22752275
&lt;Image&gt;.paste(&lt;Image&gt;, (x, y)) <span class="hljs-comment"># Draws passed image at the specified location.</span>
22762276
</code></pre>
2277-
<pre><code class="python language-python hljs">&lt;Image&gt; = &lt;Image&gt;.filter(&lt;Filter&gt;) <span class="hljs-comment"># `&lt;Filter&gt; = ImageFilter.&lt;name&gt;(&lt;args&gt;)`</span>
2278-
&lt;Image&gt; = &lt;Enhance&gt;.enhance(&lt;float&gt;) <span class="hljs-comment"># `&lt;Enhance&gt; = ImageEnhance.&lt;name&gt;(&lt;Image&gt;)`</span>
2277+
<pre><code class="python language-python hljs">&lt;Image&gt; = &lt;Image&gt;.filter(&lt;Filter&gt;) <span class="hljs-comment"># Use ImageFilter.&lt;name&gt;(&lt;args&gt;) for Filter.</span>
2278+
&lt;Image&gt; = &lt;Enhance&gt;.enhance(&lt;float&gt;) <span class="hljs-comment"># Use ImageEnhance.&lt;name&gt;(&lt;Image&gt;) for Enhance.</span>
22792279
</code></pre>
22802280
<pre><code class="python language-python hljs">&lt;array&gt; = np.array(&lt;Image&gt;) <span class="hljs-comment"># Creates a 2d/3d NumPy array from the image.</span>
22812281
&lt;Image&gt; = Image.fromarray(np.uint8(&lt;array&gt;)) <span class="hljs-comment"># Use `&lt;array&gt;.clip(0, 255)` to clip values.</span>
22822282
</code></pre>
22832283
<div><h3 id="modes-1">Modes</h3><ul>
22842284
<li><strong><code class="python hljs"><span class="hljs-string">'L'</span></code> - Lightness (greyscale image). Each pixel is an int between 0 and 255.</strong></li>
22852285
<li><strong><code class="python hljs"><span class="hljs-string">'RGB'</span></code> - Red, green, blue (true color image). Each pixel is a tuple of three ints.</strong></li>
2286-
<li><strong><code class="python hljs"><span class="hljs-string">'RGBA'</span></code> - RGB with alpha. Low alpha (i.e. forth int) makes pixel more transparent.</strong></li>
2286+
<li><strong><code class="python hljs"><span class="hljs-string">'RGBA'</span></code> - RGB with alpha. Low alpha (i.e. forth int) makes pixels more transparent.</strong></li>
22872287
<li><strong><code class="python hljs"><span class="hljs-string">'HSV'</span></code> - Hue, saturation, value. Three ints representing color in HSV color space.</strong></li>
22882288
</ul><div><h3 id="examples">Examples</h3><div><h4 id="createsapngimageofarainbowgradient">Creates a PNG image of a rainbow gradient:</h4><pre><code class="python language-python hljs">WIDTH, HEIGHT = <span class="hljs-number">100</span>, <span class="hljs-number">100</span>
22892289
n_pixels = WIDTH * HEIGHT
@@ -2931,7 +2931,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29312931

29322932

29332933
<footer>
2934-
<aside>September 27, 2024</aside>
2934+
<aside>October 2, 2024</aside>
29352935
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29362936
</footer>
29372937

0 commit comments

Comments
 (0)