[Python] Import from file without executing imports at the top of that file

Discussão em 'Python' iniciado por Stack, Setembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I have one file, foo.py

    import UnavailableModule

    class Bob:
    def useful_func(self, arg):
    # Do useful stuff (doesn't use UnavailableModule)


    And in another file bar.py in the same directory, I need useful_func() but can't do this

    from foo.Bob import useful_func


    because it results in

    problem: [Error 126] The specified module could not be found
    An exception has occurred, use %tb to see the full traceback.


    with traceback

    C:\...\bar.py in <module>()
    ----> 1 from foo.Bob import useful_func
    C:\...\foo.py in <module>()
    ----> 1 import UnavailableModule


    Is it possible to just get useful_func() only by some other means?

    Continue reading...

Compartilhe esta Página