Search code examples
pythonimportlibrariespython-packaging

How to fix overlap of functions when importing python packages from the same folder?


I have a folder called Libs that has two files (database.py and keyManagementService.py) I'd like to import as libraries to another file outside of the Libs folder. To do that, I made an __init__.py in the Libs folder which looks like this:

from Libs.database import *
from Libs.keyManagmentService import *

The way I imported the libraries to a file outside of Libs was like this:

import Libs as db 
import Libs as kms

However, the issue is the functions from the database file overlaps with the functions from the KeyManagementService file, so if I try using db for example, the functions from kms would also show up. How can I make these libraries standalone for a lack of better wording? Thanks!


Solution

  • If you clear the content from __init__.py (but leave the empty file), you should be able to

    from Libs.database import the_exact_names_you_need
    from Libs.keyManagementService import the_names_you_need_from_this_file