Naming conventions - GideonJagen/Plando GitHub Wiki

Python Naming Conventions

General

  1. Avoid using names that are too general or too wordy. Strike a good balance between the two.
  2. Bad: data_structure, my_list, info_map, dictionary_for_the_purpose_of_storing_data_representing_word_definitions
  3. Good: user_profile, menu_options, word_definitions
  4. Don’t be a jackass and name things “O”, “l”, or “I”
  5. When using CamelCase names, capitalize all letters of an abbreviation (e.g. HTTPServer)

Packages

  1. Package names should be all lower case
  2. When multiple words are needed, an underscore should separate them
  3. It is usually preferable to stick to 1 word names

Modules

  1. Module names should be all lower case
  2. When multiple words are needed, an underscore should separate them
  3. It is usually preferable to stick to 1 word names

Classes

  1. Class names should follow the UpperCaseCamelCase convention
  2. Python's built-in classes, however are typically lowercase words
  3. Exception classes should end in “Error”

Global (module-level) Variables

  1. Global variables should be all lowercase
  2. Words in a global variable name should be separated by an underscore

Instance Variables

  1. Instance variable names should be all lower case
  2. Words in an instance variable name should be separated by an underscore
  3. Non-public instance variables should begin with a single underscore
  4. If an instance name needs to be mangled, two underscores may begin its name

Methods

  1. Method names should be all lower case
  2. Words in an method name should be separated by an underscore
  3. Non-public method should begin with a single underscore
  4. If a method name needs to be mangled, two underscores may begin its name

Method Arguments

  1. Instance methods should have their first argument named ‘self’.
  2. Class methods should have their first argument named ‘cls’

Functions

  1. Function names should be all lower case
  2. Words in a function name should be separated by an underscore

Constants

  1. Constant names must be fully capitalized
  2. Words in a constant name should be separated by an underscore