Import sub-folder modules dynamically

On 15/11/2017 at 08:07, xxxxxxxx wrote:

Hi guys,

I'm trying to import modules dynamically inside sub-folders of the plugin and can't seem to make it work. My current hierarchy looks as follow:

   |  |_folder_A
   |    |   |
   |    |   |
   |    |
   |    |_folder_B
   |    |   |
   |    |   |
   |    |
   |    |_folder_C
   |        |
   |        |

Would like to be able to access the file_A, file_B and file_C. Do you have to include an empty __init__ file inside each folder?

Apologies if this has been replied before. Just can't seem to find an answer.

Thank you very much in advance! 🙂


On 15/11/2017 at 08:28, xxxxxxxx wrote:

Yes do it like you will do for any python module, make an empty
And then after that you could use from .modules._folder_A._file_A import MyClassA

Moreover I'm sure you already read it but I suggest you to read

Here a exemple of my plugin RefractiveIndexImporter wich use Niklas py-localimport class in order to make safe import.

Hope it's help

On 15/11/2017 at 08:34, xxxxxxxx wrote:

Hi graphos,

Many thanks for your quick and awesome reply!

Will give it a try and come back with a conclusion.

Thanks again! 🙂

On 15/11/2017 at 09:06, xxxxxxxx wrote:

Graphos you're a star! Worked like a treat :).

Thank you very much again and hopefully this will help others! 😄