在 python 中有很多用于导入模块的标准缩写。我经常看到
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
我注意到所有这些都是小写的。我想不出任何异常(exception)。但是,它是区分大小写的,所以我们当然可以使用大写字母。是否有任何关于此的 PEP 标准?特别是,使用大写名称创建模块并使用大写导入它们会不会有任何问题?
例如:
import MyClass as MC
import TomAndJerry as TaJ
(请注意 - 我对个人意见并不感兴趣 - 而是是否有官方标准)
最佳答案
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 ).
关于python - python导入中的大小写标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43130046/