For example:
from urllib.request import urlopen, Request
is there any rule about the capitalization of the first letter?
For example:
from urllib.request import urlopen, Request
is there any rule about the capitalization of the first letter?
Most of the answer is in pep08 (python coding style guidelines) - basically, classes are spelled in CamelCase, everything else in lower_with_underscores.
But note that (for various reasons), this convention is not always respected in Python itself (builtins and stdlib):
quite a few classes are named in all_lower, notably the datetime
, date
, time
and timedelta
from the datetime
package, all of the builtin types (type
, property
, int
, float
, str
, list
, tuple
, dict
, set
, object
etc)
the logging
package uses mixedCase
for most functions and methods (ie logging.getLogger()
which should be logging.get_logger()
etc)
For the builtin types, there's at least an historical reason: most of those names where initially bound to functions, not to classes (I'm talking python 1.5.x or even older). For what it's worth, quite a few of them are actually still documented as being functions when they are not...
The best practices in python is to use small letter in the name of functions but, when dealing with classes we capitalize the first letter.