Rico's Nerd Cluster

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

Python - Python Packaging System

Packaging, Pip

Setuptools Entrypoints Entrypoints are a way to specify components in your package to the rest of the python space, so they can be dynamically discovered. So this enables: Console scripts (co...

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) F...

Python - Immutable And Memory View

Python has mutable and immutable objects: Mutables: bytearray list … Immutables: string bytes … 1 2 3 4 buf = bytearray(b"hello world") mv = memoryview(buf) mv2 = mv[6:11] ...

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

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'...