Browse Source

Datetime, Class, Coroutines

pull/121/head
Jure Šorn 2 years ago
parent
commit
e65b8715e2
2 changed files with 18 additions and 18 deletions
  1. 16
      README.md
  2. 20
      index.html

16
README.md

@ -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
@ -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
@ -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)

20
index.html

@ -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>
@ -570,13 +570,13 @@ to_exclusive = &lt;range&gt;.stop
&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>
@ -821,16 +821,16 @@ creature = Creature(point, direction)
<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>
@ -1903,7 +1903,7 @@ W, H = <span class="hljs-number">15</span>, <span class="hljs-number">7</span>
<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>)
@ -2881,7 +2881,7 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer>
<aside>January 26, 2022</aside>
<aside>January 27, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

Loading…
Cancel
Save