Q:

Import function manually

I'm beginner in python, and i tried to understand the from ... import ... statement.
I surprised to found that we can import function manually, and i want to ask you if it is legal.
My module:
**my_module.py**

def func1():
    print 10

def func2():
    print 20

My program:
import sys
from my_module import func1

func2() ==> ERROR!

globals()["func2"] = sys.modules["my_module"].func2

func2() ==> Printing 20!

A:

If you're asking about this line:
globals()["func2"] = sys.modules["name"].func2

Is it "legal"? Sure. I mean, the Python police won't come arrest you for it.
Is it a good idea? No. If you're just importing a function, better to do it the way you did with func1. Easier to read and understand for folks who come look at your code later; better for compatibility with static analysis tools; less likely to break in future versions of Python; etc.
If you're making a module which does something "magic" in Python like wrapping another module's functions or something, then you might want to use the capability to dynamically import and name a function that way. But for general day-to-day programming, avoid it.

