Skip to content

Commit

Permalink
Datetime, Class, Coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
gto76 committed Jan 27, 2022
1 parent dc87ae2 commit e65b871
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,11 @@ from dateutil.tz import UTC, tzlocal, gettz, datetime_exists, resolve_imaginary

### Format
```python
>>> dt = datetime.strptime('2015-05-14 23:39:00.00 +0200', '%Y-%m-%d %H:%M:%S.%f %z')
>>> dt = datetime.strptime('2015-05-14 23:39:00.00 +02:00', '%Y-%m-%d %H:%M:%S.%f %z')
>>> dt.strftime("%A, %dth of %B '%y, %I:%M%p %Z")
"Thursday, 14th of May '15, 11:39PM UTC+02:00"
```
* **`'%Z'` only accepts `'UTC/GMT'` and local timezone's code. `'%z'` also accepts `HH:MM'`.**
* **`'%Z'` only accepts `'UTC/GMT'` and local timezone's code. `'%z'` also accepts `HHMM'`.**
* **For abbreviated weekday and month use `'%a'` and `'%b'`.**

### Arithmetics
Expand Down Expand Up @@ -964,18 +964,18 @@ class <name>:
#### Str() use cases:
```python
print(<el>)
print(f'{<el>}')
raise Exception(<el>)
csv.writer(<file>).writerow([<el>])
f'{<el>}'
logging.warning(<el>)
csv.writer(<file>).writerow([<el>])
raise Exception(<el>)
```

#### Repr() use cases:
```python
print([<el>])
print(f'{<el>!r}')
>>> <el>
f'{<el>!r}'
Z = dataclasses.make_dataclass('Z', ['a']); print(Z(<el>))
>>> <el>
```

### Constructor Overloading
Expand Down Expand Up @@ -2327,7 +2327,7 @@ async def random_controller(id_, moves):
async def human_controller(screen, moves):
while True:
ch = screen.getch()
key_mappings = {259: D.n, 261: D.e, 258: D.s, 260: D.w}
key_mappings = {258: D.s, 259: D.n, 260: D.w, 261: D.e}
if ch in key_mappings:
moves.put_nowait(('*', key_mappings[ch]))
await asyncio.sleep(0.005)
Expand Down
20 changes: 10 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

<body>
<header>
<aside>January 26, 2022</aside>
<aside>January 27, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>

Expand Down Expand Up @@ -570,13 +570,13 @@
&lt;float&gt; = &lt;DTa&gt;.timestamp() <span class="hljs-comment"># Seconds since the Epoch, from DTa.</span>
</code></pre></div>

<div><h3 id="format-1">Format</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>dt = datetime.strptime(<span class="hljs-string">'2015-05-14 23:39:00.00 +0200'</span>, <span class="hljs-string">'%Y-%m-%d %H:%M:%S.%f %z'</span>)
<div><h3 id="format-1">Format</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>dt = datetime.strptime(<span class="hljs-string">'2015-05-14 23:39:00.00 +02:00'</span>, <span class="hljs-string">'%Y-%m-%d %H:%M:%S.%f %z'</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dt.strftime(<span class="hljs-string">"%A, %dth of %B '%y, %I:%M%p %Z"</span>)
<span class="hljs-string">"Thursday, 14th of May '15, 11:39PM UTC+02:00"</span>
</code></pre></div>

<ul>
<li><strong><code class="python hljs"><span class="hljs-string">'%Z'</span></code> only accepts <code class="python hljs"><span class="hljs-string">'UTC/GMT'</span></code> and local timezone's code. <code class="python hljs"><span class="hljs-string">'%z'</span></code> also accepts <code class="python hljs"><span class="hljs-string">HH:MM'</span></code>.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'%Z'</span></code> only accepts <code class="python hljs"><span class="hljs-string">'UTC/GMT'</span></code> and local timezone's code. <code class="python hljs"><span class="hljs-string">'%z'</span></code> also accepts <code class="python hljs"><span class="hljs-string">HHMM'</span></code>.</strong></li>
<li><strong>For abbreviated weekday and month use <code class="python hljs"><span class="hljs-string">'%a'</span></code> and <code class="python hljs"><span class="hljs-string">'%b'</span></code>.</strong></li>
</ul>
<div><h3 id="arithmetics">Arithmetics</h3><pre><code class="python language-python apache hljs">&lt;D/DT&gt; = &lt;D/DT&gt; ± &lt;TD&gt; <span class="hljs-comment"># Returned datetime can fall into missing hour.</span>
Expand Down Expand Up @@ -821,16 +821,16 @@
<li><strong>If only repr() is defined, it will also be used for str().</strong></li>
</ul>
<div><h4 id="strusecases">Str() use cases:</h4><pre><code class="python language-python hljs">print(&lt;el&gt;)
print(<span class="hljs-string">f'<span class="hljs-subst">{&lt;el&gt;}</span>'</span>)
<span class="hljs-keyword">raise</span> Exception(&lt;el&gt;)
csv.writer(&lt;file&gt;).writerow([&lt;el&gt;])
<span class="hljs-string">f'<span class="hljs-subst">{&lt;el&gt;}</span>'</span>
logging.warning(&lt;el&gt;)
csv.writer(&lt;file&gt;).writerow([&lt;el&gt;])
<span class="hljs-keyword">raise</span> Exception(&lt;el&gt;)
</code></pre></div>

<div><h4 id="reprusecases">Repr() use cases:</h4><pre><code class="python language-python hljs">print([&lt;el&gt;])
print(<span class="hljs-string">f'<span class="hljs-subst">{&lt;el&gt;!r}</span>'</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>&lt;el&gt;
<span class="hljs-string">f'<span class="hljs-subst">{&lt;el&gt;!r}</span>'</span>
Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span class="hljs-string">'a'</span>]); print(Z(&lt;el&gt;))
<span class="hljs-meta">&gt;&gt;&gt; </span>&lt;el&gt;
</code></pre></div>

<div><h3 id="constructoroverloading">Constructor Overloading</h3><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> &lt;<span class="hljs-title">name</span>&gt;:</span>
Expand Down Expand Up @@ -1903,7 +1903,7 @@
<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">human_controller</span><span class="hljs-params">(screen, moves)</span>:</span>
<span class="hljs-keyword">while</span> <span class="hljs-keyword">True</span>:
ch = screen.getch()
key_mappings = {<span class="hljs-number">259</span>: D.n, <span class="hljs-number">261</span>: D.e, <span class="hljs-number">258</span>: D.s, <span class="hljs-number">260</span>: D.w}
key_mappings = {<span class="hljs-number">258</span>: D.s, <span class="hljs-number">259</span>: D.n, <span class="hljs-number">260</span>: D.w, <span class="hljs-number">261</span>: D.e}
<span class="hljs-keyword">if</span> ch <span class="hljs-keyword">in</span> key_mappings:
moves.put_nowait((<span class="hljs-string">'*'</span>, key_mappings[ch]))
<span class="hljs-keyword">await</span> asyncio.sleep(<span class="hljs-number">0.005</span>)
Expand Down Expand Up @@ -2881,7 +2881,7 @@


<footer>
<aside>January 26, 2022</aside>
<aside>January 27, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

Expand Down

0 comments on commit e65b871

Please sign in to comment.