There are a lot of standard abbreviations used for importing modules in python. I frequently see
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
I notice that all of these are lower case. I can't think of any exceptions. However, it is case sensitive, so we certainly can use capital letters. Is there any PEP standard about this? In particular, would there be any problem with creating modules with capitalized names and importing them with capitalizations?
For example:
import MyClass as MC
import TomAndJerry as TaJ
(please note - I'm not really interested in personal opinions - but rather whether there are official standards)
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 ).
PEP 8 covers package and module names specifically stating:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With