Home > Back-end >  Make a nested module be available globally in python
Make a nested module be available globally in python

Time:03-13

I want to remove the nested path to import a module. Instead of importing like import common.common1.bar I want to be able to import like import bar

I have the following folder structure:

functions
|-- function_1
    |-- foo.py
common
|-- common_1
    |-- bar.py

What should I do in order to make the following import inside foo.py?

# foo.py
from bar import fun1

CodePudding user response:

just copy the bar.py in to the function_1 directory or folder. and that should be it. then you can use from bar import fun1

CodePudding user response:

Unless if you are using Python 3.3 there is a need to define the full path? If it doesn't work, try creating an empty init.py in the common_1 directory

  • Related