Home

Python packages

Python packages Bast Python project dir structure project_root/ my_project/ __init__.py main.py config.py utils/ __init__.py helper.py features/ __init__.py feature_a/ __init__.py module1.py module2.py feature_b/ __init__.py ...

Read more

Python profiler

Python profiler 性能分析和代码优化 cProfile cProfile 是 Python 内置的性能分析器,适用于对整个程序进行性能分析。 python import cProfile def my_function(): # Your function code here for i in range(10000): pass cProfile.run(‘my_function()’) line_profiler line_profiler 是一个用于逐行分析 Python 代码性能的工具。需要先安装: sh pip install line_profiler 使用方法: python from...

Read more

Comprehension

Comprehension List Comprehension: # Basic list comprehension new_list = [expression for item in iterable if condition] # Example: numbers = [1, 2, 3, 4, 5] squared = [x**2 for x in numbers if x % 2 == 0] # squares of even numbers Set Comprehension: # Basic set comprehension new_set = {expression for item in iterable if condition} # Examp...

Read more

Python Magic methods

Python Magic methods Initialization and Representation __init__(self, ...): Object constructor, initializes the object. __del__(self): Object destructor, called when the object is about to be destroyed. __repr__(self): Defines the "official" string representation of an object, used by repr() and in debugging. __str__(self): Defines the "inform...

Read more

cache

cache LRUCache (Least Recently Used Cache) Eviction Policy: Evicts the least recently used items first when the cache reaches its maximum size. Usage: Useful when you want to keep the most recently accessed items in the cache. RRCache (Random Replacement Cache) Eviction Policy: Randomly evicts cache entries when the...

Read more

Java Memory Model

Java Memory Model Reference Java Memory Model: A Comprehensive Guide [Java memory model](https://en.wikipedia.org/wiki/Java_memory_model#:~:text=The%20Java%20Memory%20Model%20(JMM,consistent%20and%20reliable%20Java%20applications.) Java Memory Model in 10 minutes

Read more