python 中导入的资本化标准
Capitalization standards in importing in python
python中有很多用于导入模块的标准缩写。我经常看到
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
我注意到所有这些都是小写的。我想不出任何例外。但是,它是区分大小写的,所以我们当然可以使用大写字母。是否有任何关于此的 PEP 标准?特别是用大写名称创建模块并用大写导入它们会不会有任何问题?
例如:
import MyClass as MC
import TomAndJerry as TaJ
(请注意 - 我对个人意见并不感兴趣 - 而是是否有官方标准)
PEP 8 covers package and module names specifically 说明:
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.
There are indeed official standards:
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.
When an extension module written in C or C++ has an accompanying
Python module that provides a higher level (e.g. more object oriented)
interface, the C/C++ module has a leading underscore (e.g. _socket ).
有一个standard。
它也经常被侵犯。最常见的例子是 cPickle
。
python中有很多用于导入模块的标准缩写。我经常看到
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
我注意到所有这些都是小写的。我想不出任何例外。但是,它是区分大小写的,所以我们当然可以使用大写字母。是否有任何关于此的 PEP 标准?特别是用大写名称创建模块并用大写导入它们会不会有任何问题?
例如:
import MyClass as MC
import TomAndJerry as TaJ
(请注意 - 我对个人意见并不感兴趣 - 而是是否有官方标准)
PEP 8 covers package and module names specifically 说明:
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.
There are indeed official standards:
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.
When an extension module written in C or C++ has an accompanying Python module that provides a higher level (e.g. more object oriented) interface, the C/C++ module has a leading underscore (e.g. _socket ).
有一个standard。
它也经常被侵犯。最常见的例子是 cPickle
。