例如我写了个模块hello.py
def print_func(args):
print("Hello " + args)
return
使用import是只相当于导入了这个模块的一个文件夹,是一个相对路径。所以每次调用函数中的模块都需要重新指定
但是使用from import *相当于将模块的所有函数都导入进来,就可以直接使用函数了
import hello
hello.print_func("World")
# 并不能直接调用print_func函数,必须将hello看成一个对象,调用对象中的函数
from hello import*
print_func("World")
#可以直接调用函数了
但是在一般情况下,推荐使用import语句,避免使用from... import*,这样可以使得程序可读性更高,也可以避免命名出错
原文:https://www.cnblogs.com/scyq/p/11864798.html