Is this a proper way?

Hello!

I am learning to use this amazing library, thank you for the excellent work you do!

Now, my goal was to create a selectbox and render a subpage within my page in my notes. This menu is dynamically created depending on the content of a specific directory. And from what I understood, it is necessary to import code as if they were modules. Here is my final code:

import streamlit as st
import os

st.write("""
# Welcome to notes
In this section, we are going to explore the knowledge that we acquired from our Math 3 classes.

Please select the topic you wish to explore
""")

files = [file for file in sorted(os.listdir('notes/problems14/')) if file != '__pycache__']
problems = {f'Problem {i}': file for i, file in enumerate(files, 1)}


option = st.selectbox(
    "**Problems homework 1.4:**",
    problems.keys(),
    index=None,
    placeholder="Choose a problem"
)

if option:
    name, _ = os.path.splitext(problems.get(option))
    module_name = f'notes.problems14.{name}'
    module = __import__(module_name, fromlist=['main'])
    page = getattr(module, 'main')
    page()

This works perfectly as I want, but my question is, is this the right way to do it? Or maybe I missed something that I haven’t quite understood.

Thank you for your time, I’ll be reading!