Python: name of a module with a two-word name

I am trying to build a really simple module with one .py source file in it and is already running at the checkpoint. I was going to name it scons-config , but import scons-config does not work in Python. I found this SO question and looked at the PEP8 style guide , but I'm a little confused, it does not talk about conventions in a nutshell.

What is the right way to handle this?

  • module name: SconsConfig? scons_config? sconsconfig? scons.config?
  • name of one .py file in it: scons-config.py? scons_config.py?

edit: I saw “using underscores is not recommended,” and it left me at a loss: should I use “sconsconfig” or “scons_config” (I think)?

+42
python naming-conventions
May 17 '10 at 19:56
source share
4 answers

If you need to, always use the underscores _ .

Using a point . won't even work, otherwise

 from scons.config import whatever 

will break.

But PEP 8 clearly describes this:

Package and Module Names

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

UPDATE:

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

But to be honest, I don’t think anyone will blame you if you use underscores and your code will work with any solution. There is always a certain level where you no longer need to care.

+50
May 17 '10 at 20:00
source share

Firstly, the module name is the same as the name of a single .py file. In Python-talk, a set of multiple .py files is a package.

PEP-8 prevents splitting package names into underscores. A quick peak in the directory of my package site shows that verbose names usually just start together (e.g. setuptools, sqlalchemy)

Module names (i.e. file names) can be broken by underscores (and I usually do this because I hate namesthatruntogethersoywardlyreadthem).

Keep only lower case (on PEP-8). This avoids problems when switching from case-sensitive files that are not case-sensitive and vice versa.

+10
May 17 '10 at 20:08
source share

In addition to PEP-8, you can also learn how to deal with this problem using native Python modules.

If you compare the native Python 2 modules with that of Python 3 , you will see that the new trend with official developers is to avoid uppercase and underscore. For example, ConfigParser in Python 2 becomes ConfigParser in Python 3.

Looking at this, the best course of action would be to avoid capitalization and underlining and just join the words together, i.e. sconsconfig .

+3
Apr 19 '16 at 10:59
source share

- - This is not a race. The symbol is used for the minus operator. The same can be said in most programming languages. Use _ or else nothing.

+2
May 17 '10 at
source share



All Articles