是否有必要在程序中以两种不同的方式导入相同的模块? [英] Is there a point to import the same module in two different ways in a program?
本文介绍了是否有必要在程序中以两种不同的方式导入相同的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否需要以通配符和非通配符方式导入,例如:
Is there a point to import as both wildcard and non-wildcard manner like:
import spam as sp
from spam import *
?
推荐答案
当您将垃圾邮件作为sp导入时,请确保与其他导入命令没有冲突:
When you import spam as sp, you make sure that there are no conflicts with other import commands:
import spam as sp
import myfunctions as my
sp.foo()
my.foo()
这是按预期工作,但不是:
This is working as expected, but this isn't:
from spam import *
from myfunctions import *
foo()
foo() #Which foo() is meant? UNCLEAR!!!
当您通过使用导入垃圾邮件作为sp $ c来避免此问题时$ c>,为什么你要使用
来自垃圾邮件导入*
呢?我认为这没有任何意义。
When you avoid this problem by using import spam as sp
, why would you want to use from spam import *
anyways? I don't think there is any point in this.
这篇关于是否有必要在程序中以两种不同的方式导入相同的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文