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:
|Prefix||Type of variable|
|i_||Integer or numeric in general if you don’t use f_|
|f_||Float. Optional use|
|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|
|l_[x]_||Local variable. Optional use.|
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.