-
Notifications
You must be signed in to change notification settings - Fork 135
Python guidelines
Oliver Lantwin edited this page Dec 11, 2025
·
4 revisions
General guidelines to improve the quality and readability of our python code. For python, see the C++ guidelines.
- PREFER iterating over containers to indexing containers manually
- PREFER argparse over getopt
- PREFER new style to old style string formatting, see also here
- ALWAYS use ruff-format (for new code) and ruff-check
- ALWAYS place import statements at the top of the file
- NEVER run non-trivial code at the top-level scope of your module, so that it can be imported without side-effects. INSTEAD, hide this code behind an
if __name__ == "__main__":condition
- PREFER STL vectors or RVecs or GenVector over TVectorT
- PREFER STL containers or RTensor over TMatrix
- PREFER using
len()instead of.size()and.GetEntries()(supported for STL containers, TCAs, TTrees, Pythia8 events and many other data types)