MT Notation for Python

Last update: 2022-05-11 18:41 IST

Maria Teresa notation for Python (also known as MT notation) is intended to help developers with the programming style and the variable names in Python.
As the type hinting of Python is weak, the notation helps to identify bugs by seeing, with the prefix, what kind of variable was it intended for.

It is inspired by the old and useful Hungarian notation.

I would like to credit and to show gratitude to a great person and developer, that passed away many years ago, and who shown me for the very first time the advantages of using prefix notation when coding, long time ago much before PHP appeared. In loving memory of Emilio.

Specification v. 1.0 Created on 1999-07-01
Specification v. 1.12. Last modified 2020-04-10
Specification v. 1.20. Last modified 2021-07-16
Specification v. 1.21. Last modified 2021-08-11

In general following PEP-8, with some additions.

The names have to be significant, so auto-descriptive.
Do not use k or i even for loops.
Use i_loop i_counter i_num_matches etcetera instead.

It recommends some prefixes:

It is not recommended to use Global variables, but if you have to use them variables defined in the main body that are intended to used publicly, or used inside many methods and functions, being accessed globally will start with:

p_

Other prefixes:

PrefixType of variable
s_String
i_Integer or numeric in general if you don’t use f_
f_Float. Optional use
b_Boolean
h_ or d_Array hash, also called dictionary
a_Array List, with numeric keys
t_Tuples. Like Lists, but immutables. Optional use
c_Counters. From collections.Counter()
o_Object / Class / Resource or Recordset
by_Bytes.
j_JSON variables
l_[x]_Local variable. Optional use.
For instance:
l_o_subprocess inside a method or function in opposition to the o_subprocess from the global scope.

Class names in Camel Case and Constants in Uppercase.

If you use an array were all the values are String, you can prepend a_s_

If you use a dictionary where keys are String and values are Integer you can prepend d_s_i_

If you use a dict where keys are String and values are Arrays you can prepend d_s_a_

An Array of tuples of with a String and Integer could be represented with the prefix a_t_s_s_ or in a simplified way a_t_

Another advantage is that it will prevent collisions. For example if you sort an array you may be tempted to name that variable sorted. That would suppose a collision with function sorted(). But with MT Notation you would use a_sorted so you would never have the risk of a collision.

The MT notation can also be used to build SQL queries. It is specially useful for locating errors quickly in JOINS (like comparing VARCHAR and INT) and in Stored Procedures.

Views: 8,139 views

Rules for writing a Comment


  1. Comments are moderated
  2. I don't publish Spam
  3. Comments with a fake email are not published
  4. Disrespectful comments are not published, even if they have a valid point
  5. Please try to read all the article before asking, as in many cases questions are already responded