Spyder的IDE中关于“from module import *” 警告

(一)“from module import *” 警告

一般不建议使用from module import * ,最好是导入相对应的函数即可!

如果出现警告unable to detect undefined names,解决办法:

Your IDE is complaining, not Python. When you do from simple import *, you import everything exposed by simple. This is typically not recommended because it pollutes the global namespace and may implicitly overwrite an existing object.

You get a warning instead of an error because this behavior is not always bad. Having an init.py file that exposes objects from sub-modules is a very common pattern. As long as you understand the potential risks, just silence the warning:

不推荐

from .input import *  # NOQA

If your modules don’t expose many objects, just import them by name:

推荐

from .input import A, B, C

This has the benefit of allowing Python code analysis tools to better understand your code and warn you of potential issues.

关于#NOQA这个注释的作用是,告诉PEP8规范检测工具,这个地方不需要检测。也可以在一个文件第一行增加 # NOQA 来告诉规范检测工具,这个文件不用检查。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值