Browse Source

Match statement

pull/144/merge
Jure Šorn 4 months ago
parent
commit
df388070a1
3 changed files with 3 additions and 3 deletions
  1. 2
      README.md
  2. 2
      index.html
  3. 2
      parse.js

2
README.md

@ -2231,7 +2231,7 @@ match <object/expression>:
>>> match Path('/home/gto/python-cheatsheet/README.md'):
... case Path(
... parts=['/', 'home', user, *_]
... ) as p if p.stem.lower() == 'readme' and p.suffix.lower() in ['.md', '.txt']:
... ) as p if p.name.lower().startswith('readme') and p.is_file():
... print(f'{p.name} is a readme file that belongs to user {user}.')
'README.md is a readme file that belongs to user gto.'
```

2
index.html

@ -1827,7 +1827,7 @@ first_element = op.methodcaller(<span class="hljs-string">'pop'</span>, <span
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">match</span> Path(<span class="hljs-string">'/home/gto/python-cheatsheet/README.md'</span>):
<span class="hljs-meta">... </span> <span class="hljs-keyword">case</span> Path(
<span class="hljs-meta">... </span> parts=[<span class="hljs-string">'/'</span>, <span class="hljs-string">'home'</span>, user, *_]
<span class="hljs-meta">... </span> ) <span class="hljs-keyword">as</span> p <span class="hljs-keyword">if</span> p.stem.lower() == <span class="hljs-string">'readme'</span> <span class="hljs-keyword">and</span> p.suffix.lower() <span class="hljs-keyword">in</span> [<span class="hljs-string">'.md'</span>, <span class="hljs-string">'.txt'</span>]:
<span class="hljs-meta">... </span> ) <span class="hljs-keyword">as</span> p <span class="hljs-keyword">if</span> p.name.lower().startswith(<span class="hljs-string">'readme'</span>) <span class="hljs-keyword">and</span> p.is_file():
<span class="hljs-meta">... </span> print(<span class="hljs-string">f'<span class="hljs-subst">{p.name}</span> is a readme file that belongs to user <span class="hljs-subst">{user}</span>.'</span>)
<span class="hljs-string">'README.md is a readme file that belongs to user gto.'</span>
</code></pre></div>

2
parse.js

@ -113,7 +113,7 @@ const MATCH_EXAMPLE =
'<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">match</span> Path(<span class="hljs-string">\'/home/gto/python-cheatsheet/README.md\'</span>):\n' +
'<span class="hljs-meta">... </span> <span class="hljs-keyword">case</span> Path(\n' +
'<span class="hljs-meta">... </span> parts=[<span class="hljs-string">\'/\'</span>, <span class="hljs-string">\'home\'</span>, user, *_]\n' +
'<span class="hljs-meta">... </span> ) <span class="hljs-keyword">as</span> p <span class="hljs-keyword">if</span> p.stem.lower() == <span class="hljs-string">\'readme\'</span> <span class="hljs-keyword">and</span> p.suffix.lower() <span class="hljs-keyword">in</span> [<span class="hljs-string">\'.md\'</span>, <span class="hljs-string">\'.txt\'</span>]:\n' +
'<span class="hljs-meta">... </span> ) <span class="hljs-keyword">as</span> p <span class="hljs-keyword">if</span> p.name.lower().startswith(<span class="hljs-string">\'readme\'</span>) <span class="hljs-keyword">and</span> p.is_file():\n' +
'<span class="hljs-meta">... </span> print(<span class="hljs-string">f\'<span class="hljs-subst">{p.name}</span> is a readme file that belongs to user <span class="hljs-subst">{user}</span>.\'</span>)\n' +
'<span class="hljs-string">\'README.md is a readme file that belongs to user gto.\'</span>\n';

Loading…
Cancel
Save