[Python] How do i ask user to choose a method in python?

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create my first project where i make my own module . i am trying to create a python project where a python file imports a module whose init python file automatically detects the python files execpt for itself

    # __init__.py
    import os
    list_files = os.listdir(path="/home/inf-everything/projects/python/module")
    def filter_py(file_name:str) -> bool:
    if file_name.endswith(".py") and file_name != "__init__.py":
    return True
    else:
    return False
    def remove_py_extension(file_name:str) -> str:
    file_name_list = list(file_name)
    sorted_file_list = file_name_list[len(file_name_list)-4::-1]
    sorted_file_list2 = sorted_file_list[::-1]
    sorted_file_name = "".join(sorted_file_list2)
    return sorted_file_name

    python_files = list(filter(filter_py,list_files))
    python_files_without_py_extension = list(map(remove_py_extension,python_files))
    __all__ = python_files_without_py_extension



    output when i run it

    /home/inf-everything/projects/python/.venv/bin/python /home/inf-everything/projects/python/module/__init__.py
    ['test1', 'morgue_algo']


    here is the code of the file that imports the module

    import module
    #dir(test1)[:7:-1]]
    list_files = module.__all__

    print(module.__all__)
    method_to_use = input("enter a method : ")

    string = input("enter your string :") # prompting the user with the "string" to enter something which will be stored in the form of string

    try :
    module.test1.hello(string)
    pass
    except Exception as e:
    print(e)


    #type: ignore


    then prompts user to select a method thats listed then use the function to fromat the inputted string but i am stuck in maling the user to select a method without manually updating the file that imports the module or making a seprate python file

    i tried using lambda but they didnt work so i am here

    Continue reading...

Compartilhe esta Página