是否有必要在程序中以两种不同的方式导入相同的模块?

编程入门 行业动态 更新时间:2024-10-25 22:36:58
本文介绍了是否有必要在程序中以两种不同的方式导入相同的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否需要以通配符和非通配符方式导入,例如:

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.

更多推荐

是否有必要在程序中以两种不同的方式导入相同的模块?

本文发布于:2023-10-26 21:52:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531450.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两种   有必要   中以   模块   方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!