Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do python module names have some uppercase letters but are always imported in lowercase?

Whenever I see references to modules like SciPy and NumPy the first letter of each part is capitalized. However they must be imported with all lowercase letters. Why is there this difference?

like image 589
redwood_gm Avatar asked Jun 05 '18 21:06

redwood_gm


People also ask

Can Python modules have capital letters?

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.

Why would you write a variable name in all uppercase all capital letters in Python?

Variables can only contain upper and lowercase letters (Python is case-sensitive) and _ (the underscore character). Hence, because we can't have spaces in variable names a common convention is to capitalize the first letter of every word after the first.

Does Python distinguish uppercase and lowercase?

A programming language is said to be case sensitive if it distinguishes between uppercase and lowercase letters. Python is a `case sensitive programming language. Variable, functions, modules and package names are written in lowercase by convention.

Why is lowercase a greater than uppercase A in Python?

Python compares strings lexicographically, using the constituent characters based on their ASCII or Unicode code points. The same principle applies for Python3. In ASCII, and therefore in Unicode, lowercase letters are greater than all uppercase letters.


1 Answers

The difference is basically in branding. As per the style guide: https://www.python.org/dev/peps/pep-0008/#package-and-module-names module names should be short and all lower cased. One reason for that is that when you are importing a module, it would be inconvenient if you had to remember all the capitalizations in the name. Big packages like NumPy and SciPy follow this convention, but when they are referring to themselves (or when others are referring to them) they like to include the stylistic capitalizations. It's mostly a style/branding choice.

like image 199
enumaris Avatar answered Nov 09 '22 16:11

enumaris