python:命名具有两个单词名称的模块 [英] python: naming a module that has a two-word name

查看:119
本文介绍了python:命名具有两个单词名称的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个带有一个.py源文件的非常简单的模块组合在一起,并且已经遇到了障碍.我打算将其称为scons-config,但import scons-config在Python中不起作用.我发现了这个SO问题,然后看了

I'm trying to put together a really simple module with one .py source file in it, and have already run into a roadblock. I was going to call it scons-config but import scons-config doesn't work in Python. I found this SO question and looked at PEP8 style guide but am kind of bewildered, it doesn't talk about two-word-name conventions.

解决这个问题的正确方法是什么?

What's the right way to deal with this?

  • 模块名称:SconsConfig? scons_config? sconsconfig? scons.config?
  • 其中的单个.py文件的
  • 名称:scons-config.py? scons_config.py?
  • module name: SconsConfig? scons_config? sconsconfig? scons.config?
  • name of the single .py file in it: scons-config.py? scons_config.py?

我确实看到不鼓励使用下划线",这使我陷入了死胡同:我应该使用"sconsconfig"还是"scons_config"(我想其他的都可以了)?

edit: I did see "the use of underscores is discouraged" and that left me at a dead end: should I use "sconsconfig" or "scons_config" (I guess the other ones are out)?

推荐答案

如有必要,请始终使用下划线_.

If you have to, always use underscores _.

使用点.甚至无法正常工作,否则

Using a dot . would not even work, otherwise

from scons.config import whatever

会休息.

但是 PEP 8 清楚地描述了它:

包装和模块名称

Package and Module Names

模块应具有简短的全小写名称. 下划线 可以使用 如果它提高了可读性,则在模块名称中输入. Python 软件包应 也具有短的全小写名称,尽管下划线的用法是 灰心.

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

更新:

直接针对您的问题:我认为sconsconfig很好.它不太长,可读性很强.

To directly target your question: I think sconsconfig is fine. It is not too long and quite readable.

但是,老实说,如果您使用下划线,并且任何决定都可以运行您的代码,那么我认为没有人会责备您.始终在某个特定级别上,您不再需要 了.

But honestly, I don't think anyone will blame you if you use underscores and your code will run with either decision. There is always a certain level where you should not care that much anymore.

这篇关于python:命名具有两个单词名称的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆