如果我在我的代码中定义了一个函数,让我们调用 foo(),我使用以下代码:
from mod1 import *
使用 mod1 包含一个也具有相同名称的函数 foo() 并调用 foo() 函数,这会在评估它时覆盖我对函数的原始定义吗?
据我所知会。
您需要重命名foo()已构建的函数或将模块输入更改为读取 
import mod1并随后定义该foo()函数的任何mod1使用mod1.foo()
取决于函数在哪里:
def foo():
    pass
from mod1 import *
foo() # here foo comes from mod1
# ------- 
# another interesting case
def foo():
    from mod1 import *
    foo() # this will also call foo from mod1
foo()     # but this one is still the foo defined above.     
# ---------
# The opposite 
from mod1 import *
def foo():
    pass
foo() # here foo is the one defined above
无论如何,from module import *这被认为是一种非常糟糕且容易出错的做法。它在 C++ 中是一种类似的using namespace std;东西。尽可能避免它。
我得到以下信息:
文件 mod1.py 包含
def foo():
    print "hello foo"
然后我启动 python 解释器并执行以下操作:
>>> def foo():
...     print "hello world"
... 
>>> from mod1 import *
>>> foo()
hello foo
>>>
所以是的,它会覆盖。
除非你这样做,否则一个新的
def foo():
    print "new foo"
在这种情况下,它将打印“new foo”
def foo():
    print 'Hello A'
>>> def foo():
...     print 'Hello 1'
... 
>>> foo()
Hello 1
>>> from a import *
>>> foo()
Hello A
>>> def foo():
...     print 'Hello 2'
... 
>>> foo()
Hello 2
这取决于函数定义和import语句的相对顺序。第二个执行的将覆盖第一个。