本文介绍了是否有必要在程序中以两种不同的方式导入相同的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否需要以通配符和非通配符方式导入,例如:
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 ,为什么你要使用来自垃圾邮件导入* 呢?我认为这没有任何意义。
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.
更多推荐
是否有必要在程序中以两种不同的方式导入相同的模块?
发布评论