Reputation: 23837
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)
Upvotes: 4
Views: 10517
Reputation: 8927
There is a standard.
It also gets violated not infrequently. The most common example of off the top of my head is cPickle
.
Upvotes: 1
Reputation: 5107
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 ).
Upvotes: 7
Reputation: 155458
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.
Upvotes: 5