0

In python, I'd like to import my_fun() from mymodule but I still wish to call it as mymodule.my_fun(). How can I do that?

So far I know only about the following unsatisfying options:

import mymodule            # imports all functions :(
mymodule.my_fun()

from mymodule import my_fun 
my_fun()                   # not referred as mymodule.my_fun() :(

Something like this would be great:

from mymodule import my_fun 
mymodule.my_fun()          
Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91
  • There's no smooth way of doing it. You can do `from mymodule import my_fun as momodule__my_fun` if you just want the name to be logical. But it doesn't give you any benefits. Read the possible duplicate. – Torxed Aug 18 '13 at 21:15
  • Yes, thank you both! My question is an exact duplicate indeed. I voted up the question and the answer where you referred. – Barney Szabolcs Aug 18 '13 at 21:45

0 Answers0