Skip to content

Python - Match-Case Statement

Python3
1 1 162
  • Warum wollte iich unbedingt mal endlci Python 3.10 ausprobieren? Wegen dem Match-Case Statement. Ich wollte mal ausprobieren, ob das angenehmer zu programmieren ist, als diese verschachtelten if-else Statements.

    Aus der Anleitung

    match subject:
        case <pattern_1>:
            <action_1>
        case <pattern_2>:
            <action_2>
        case <pattern_3>:
            <action_3>
        case _:
            <action_wildcard>
    

    Einen schönen Beitrag habe ich auch im Internet gefunden. Ok, hier mal ein Beispiel.

    match_list = [backup_data[row].rest, bool(backup_data[row].password)]
    match match_list:
    

    Ich erzeuge eine Liste, mit zwei Variablen.

    • backup_data[row].rest - 0/1
    • backup_data[row].password - password/keines gesetzt

    Das kann man dann abfragen mit

    case ["0", False]:
    

    Dann gibt es in meinem Fall noch

    case["0", True]:
    case["1", False]:
    case["1", False]:
    

    Dann könnten man noch das hier machen

    case _:
    

    Der fängt alles ab, was vorher nicht erfolgreich war.

    Ich finde das recht praktisch, weil es doch um einiges angenehmer zu lesen ist.

  • 0 Votes
    1 Posts
    200 Views
    No one has replied
  • PyWebIO vs. Flask

    Python3 pywebio flask linux python
    2
    0 Votes
    2 Posts
    277 Views
    FrankMF
    Mist, jetzt habe ich auch noch Streamlit gefunden. Jetzt geht mir langsam die Zeit aus...
  • Python - Formatumwandlung str -> float

    Python3 python
    1
    0 Votes
    1 Posts
    959 Views
    No one has replied
  • Python - Frameworks

    Python3 python pywebio flet
    2
    0 Votes
    2 Posts
    208 Views
    FrankMF
    Und mal hier parken https://www.youtube.com/watch?v=Tucr8Ta-kq4&t=1911s
  • Vorstellung Restic UI als PyWebIO Version

    PyWebIO restic-ui pywebio python
    7
    0 Votes
    7 Posts
    363 Views
    FrankMF
    https://gitlab.com/Bullet64/restic_ui_pywebio/-/commit/45c83cd8c38f466e427046b0f123c23def1bd7ca
  • PyWebIO - put_buttons

    PyWebIO pywebio python
    2
    1
    0 Votes
    2 Posts
    242 Views
    FrankMF
    Und noch eine kleine Übung, wie man den Buttton abhängig von einem Value enabled/disabled # we build header and tdata for table tab_mount = [] for count, value in enumerate(backups): if count == 0: tab_mount.append(['No.', 'Backup name of the restic data backup', 'Actions']) if backups[value].init == "0": tab_mount.append([count + 1, backups[count].name, put_buttons([ dict(label='Mount', value='Mount', color='primary', disabled=True), dict(label='UMount', value='UMount', color='primary', disabled=True), dict(label='Restore', value='Restore', color='primary', disabled=True), ] , onclick=partial(actions, count + 1)) ]) else: tab_mount.append([count + 1, backups[count].name, put_buttons([ dict(label='Mount', value='Mount', color='primary'), dict(label='UMount', value='UMount', color='primary'), dict(label='Restore', value='Restore', color='primary'), ], onclick=partial(actions, count + 1)) ])
  • PyWebIO - Footer bearbeiten

    PyWebIO pywebio python
    1
    1
    0 Votes
    1 Posts
    162 Views
    No one has replied
  • Qt 5 Designer

    Python3 python
    1
    4
    0 Votes
    1 Posts
    147 Views
    No one has replied