[Python] import of a function from nested structure

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    Consider this directory structure:

    a-a
    | b
    | c
    | print.py


    Basically a-a/b/c. and print.py inside that directory. The contents of print.py looks like as :

    def print_5():
    print("5")


    def print_10():
    print("10")



    I want to import and use these functions into my current file at the level of a-a. Structure :

    ls
    a-a test.py


    How do I do that?

    Inside test.py, I tried importing all the functions as :

    from a-a.b.c import f

    print_5()


    And it gives error as SyntaxError: invalid syntax that I understand. So, I moved 'a-a' to 'a_a' and it started to give me ModuleNotFoundError: No module named 'a_a'. I know it can be a trivial thing, just not coming in place for me.

    Continue reading...

Compartilhe esta Página