[Python] Create a path structure that can be navigated like classes

Discussão em 'Python' iniciado por Stack, Outubro 23, 2024.

  1. Stack

    Stack Membro Participativo

    Assume there is the following path structure in a storage account that I've created myself:

    basepath (e.g. /mount/basefolder/)
    ├── folder_a
    ├── folder_b
    ├── folder_c
    | ├── folder_c1
    | ├── folder_c2
    | └── a_file.txt
    | └── folder_d
    | ├── another_file.csv
    | ├── folder_d1
    └── folder_d2
    └── my_table.xlsx


    I'd like to have a class (or something else) Path that returns the base path "/mount/basefolder/" when calling it. So, pasting Path to the console should return "/mount/basefolder/". When writing Path. in my IDE and pressing tabulator the IDE should suggest the different options of the second hierarchy of folders/files: "folder_a", "folder_b", "folder_c" and "folder_d". Calling Path.folder_b should return "/mount/basefolder/folder_b/". When writing Path.folder_c.to the IDE it should suggest the options "folder_c1", "folder_c2" and "a_file.txt" and so on.

    The idea is that I can easily navigate the paths that exist using dots and that calling it returns the string to the actual path in my storage account. But how do I build something like that? Of course, classes are required. I thought that StrEnums might help but I couln't figure out how to set it up :(.

    Continue reading...

Compartilhe esta Página