首页 > IT职业 > IT职场 > python中from...import的使用

Python 的 from … import 语句指定的部分可以从模块导入到当前脚本中。
# Filename: test.py
#导入模块
from printHello import hello
# 现在可以调用模块里包含的函数了
hello("Python")
我们改为使用from…import语句,即from模块导入函数,这样我们就可以只导入我们需要的函数,而不是导入整个模块。调用时直接写函数名而不是模块名。
以上就是python中from … import的使用,希望能对大家有所帮助,更多知识尽在python学习网。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1594/viewspace-2830651/ ,如需转载,请注明出处,否则将追究法律责任。