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 ScipyCalculator
use import paths, not filenames (e.g. pandas.calculator) to avoid module name collisions
from X (X is actually a file name)
use alias
as X
in case you have the same class names
__name__
my_project/
├── person.py
└── main.py
🔹 person.py
person.py
class 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.py
from person import Person
def main():
print("Running main.py")
person = Person("Alice")
print(person.greet())
if __name__ == "__main__":
main()
> python main.py
Output:
Running main.py
Hi, I'm Alice
> python person.py
Output:
Running person.py directly
Hi, I'm Tester
__init.py__
Last updated
Was this helpful?