本文基于 Frost Ming “friendly python” 标签下的文章,整理出偏向工程实践的开发范式、规范与典型好/坏代码范式示例。重点是“对使用者友好 + 对维护者友好”,并强调在 Python 中利用语言特性与生态扩展点进行合理抽象。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| import opendal | |
| # A ~300MB file with compression='none' | |
| row_count = 18000000 | |
| df = pd.DataFrame({ | |
| 'A': np.random.randn(row_count), # float64 | |
| 'B': np.random.randint(0, 100, size=row_count), # int32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| # git clone https://github.com/fsspec/s3fs/ | |
| # cd s3fs | |
| # pip install -e . | |
| import s3fs | |
| print(s3fs.__file__) | |
| # A ~300MB file with compression='none' | |
| row_count = 18000000 |