Search code examples
pythonmodulepackagenamespaces

how to call function from one of the module inside a package without mentioning modules name?


I've got callMe() inside mypack.py. But to make things clear I've moved my functions to separate module

|mypack
  |__init__.py
  |mycalls.py
  |...

but i want to keep how they were called before that changes:

import mypack
mypack.callMe()

is there proper way to do this?

i know that it could be done with __init__.py using import all but is that a good practice?

from .mycalls import *

Solution

  • Although, I'm not quite sure why this would be helpful or in which use case this could be beneficial, if you insist on calling mypack.mycalls.* as mypack.* you can simply do:

    import mypack.mycalls as mypack
    

    Then you're able to do:

    mypack.callMe()