Python
Tooling
uv (https://github.com/astral-sh/uv)
An extremely fast Python package and project manager, written in Rust.
A single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more.
Syntax
Different types of methods
class Example:
    def __init__(self, value):
        self.value = value
    def instance_method(self):
        print(f"Instance method, self.value = {self.value}")
    @classmethod
    def class_method(cls):
        print(f"Class method, cls = {cls.__name__}")
    @staticmethod
    def static_method():
        print("Static method (no self or cls)")
e = Example(42)
e.instance_method()   # Bound to instance
Example.class_method()  # Bound to class
Example.static_method()  # No binding
Type
Decorator
First Parameter
Used For
Instance
(none)
self
Behavior tied to object instance
Class Method
@classmethod
cls
Behavior tied to class (like factories)
Static Method
@staticmethod
none
Utility functions not tied to class/instance
Import
from pandas.calculator import Calculator as PandasCalculator
from scipy.calculator import Calculator as ScipyCalculatoruse import paths, not filenames (e.g. pandas.calculator) to avoid module name collisions
from X (X is actually a file name)
use alias
as Xin case you have the same class names
__name__
my_project/
├── person.py
└── main.py🔹 person.py
person.pyclass Person:
    def __init__(self, name: str):
        self.name = name
    def greet(self):
        return f"Hi, I'm {self.name}"
# This block runs only if you execute person.py directly
if __name__ == "__main__":
    print("Running person.py directly")
    test_person = Person("Tester")
    print(test_person.greet())🔹 main.py
main.pyfrom person import Person
def main():
    print("Running main.py")
    person = Person("Alice")
    print(person.greet())
if __name__ == "__main__":
    main()> python main.pyOutput:
Running main.py
Hi, I'm Alice> python person.pyOutput:
Running person.py directly
Hi, I'm Tester__init.py__
Last updated
Was this helpful?