Re: Polymorphic imports

2021-09-22 Thread Chris Angelico
On Thu, Sep 23, 2021 at 4:20 AM Dennis Lee Bieber wrote: > > The other alternative may be > https://docs.python.org/3/library/functions.html#__import__ > I wouldn't recommend calling a dunder. If you just want to pass a text string and get back a module, importlib is a better choice. Chr

Re: Polymorphic imports

2021-09-22 Thread Dennis Lee Bieber
On Tue, 21 Sep 2021 18:58:31 +, Travis Griggs declaimed the following: >from lib import paths >import paths.dynamic_client_module() > >But this seems to not work. Import can only take real modules? Not programatic >ones? Consider "import" to be equivalent to a compile-time operatio

Re: Polymorphic imports

2021-09-21 Thread Chris Angelico
On Wed, Sep 22, 2021 at 6:05 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2021-09-22 at 05:10:02 +1000, > Chris Angelico wrote: > > > You can dynamically import modules using importlib.import_module(), > > but an easier way might just be a conditional import: > > > > # client/__init__.py

Re: Polymorphic imports

2021-09-21 Thread 2QdxY4RzWzUUiLuE
On 2021-09-22 at 05:10:02 +1000, Chris Angelico wrote: > You can dynamically import modules using importlib.import_module(), > but an easier way might just be a conditional import: > > # client/__init__.py > if some_condition: > import module_a_default as module_a > else: > import module

Re: Polymorphic imports

2021-09-21 Thread Chris Angelico
On Wed, Sep 22, 2021 at 4:59 AM Travis Griggs wrote: > > I guess this is kind of like mocking for testing. I have a simple module > that's imported in a number of other spots in my program. There's a condition > in the OS/filesystem where I'd like to import a polymorphically compatible > varian

Polymorphic imports

2021-09-21 Thread Travis Griggs
I guess this is kind of like mocking for testing. I have a simple module that's imported in a number of other spots in my program. There's a condition in the OS/filesystem where I'd like to import a polymorphically compatible variant of the same module. Can this be accomplished in a sort of once