Skip to content

Commit

Permalink
Match statement
Browse files Browse the repository at this point in the history
  • Loading branch information
gto76 committed Oct 13, 2024
1 parent 34bda0c commit df38807
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
```
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
<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>
Expand Down
2 changes: 1 addition & 1 deletion parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit df38807

Please sign in to comment.