Rico's Nerd Cluster

「离开世界之前 一切都是过程」

Python - Poetry Packaging System and Pip

Poetry, Pip

Introduction Using Poetry is highly recommended because it simplifies dependency management and packaging, even when not using virtual environments. Environments without Poetry can install poetry ...

Python - How To Write Pytest

Pytest Is The New Black (Compared To Unittest)

Run Pytest Run a specific test file pytest path/to/test_file.py Run a test in it: pytest path/to/test_file.py::test_function_name Assert For integer assertions: 1 assert (1==1) ...

Python - Functools

lru_cache

lru_cache One subtle but very real bug when using functools.lru_cache with mutable objects is cache poisoning caused by mutability. The cache stores and returns the exact same object references ...

Python - Immutable And Memory View

Mutable vs Immutable Objects Python objects are either mutable or immutable: Mutable Immutable bytearray, list, dict, set str, bytes, int, tuple ...

Python - Python Mixin Classes

MRO

Mixins A mixin is a small, focused class that provides methods to be “mixed in” to other classes via multiple inheritance. Mixins let you bundle reusable behaviors and add them to any class, keepi...

Python - File Management

os

File Path Processing os.path.basename("/home/foo/Downloads/000000.pcd") gives the string after the last “/”. So here we get: 000000.pcd os.path.splitext("/home/foo/Downloads/000000.pcd") give...

Python - Enums, dataclass

Enum, IntEnum

IntEnum IntEnum’s members are ints, while enum instance’s members are its own class Enum: Base class for creating enumerated constants. IntEnum: Base class for creating enumera...

Python - Python Iterables

Iterable, Itertools, Round Robin Counter

What is An Iterable An iterable is any object that returns an iterator, which allows you to iterate its elements. Some common examples include lists, dictionaries, sets, and strings. Iterating ove...

Python - Jupyter Notebook Common Magic Commands

Jupyter Notebook Common Magic Commands

Magic command %command is a function in IPython. Make sure matplotlib is rendered inline Immediately autoreload modules if they are changed outside 1 2 3 4 5 6 7 8 9 10 11 %matplotlib inlin...

Python - Python Misc, os, shutil

Sys, Print, Argparse Path-Related Utils, HDF5

sys Check current python version 1 2 3 4 if sys.version_info.major == 3 and sys.version_info.minor == 10: print("Python version is 3.10") else: print(f"Python version is not 3.10, it'...