Tips and Traps¶
Starting from Python 3.7,
dict
preserves insertion order (i.e.,dict
is ordered). There is no need to useOrderedDict
any more in Python 3.7+. However,set
in Python is implemented as an unordered hashset and thus is neither ordered nor sorted. A trick to dedup an iterablevalues
Install Python in macOS
There are a few ways to install Python in Mac.
-
Install system-wide via the official Python installation package.
-
Install locally using Homebrew (recommended).
You should avoid installing multiple versions of Python in your system. It usually brings more troubles than conveniences. Python virtual environemnts ( via uv ) and Docker containers are …
Working with Spreadsheet in Python
It is suggested that you avoid using Excel files (or other spreadsheet tools) for storing data. Parquet file is currently the best format for storing table-like data. If you do want to interact and manipulate your data using Excel (or other spreadsheet tools), dump your data into CSV files and …
Summary on Random Number Generators
Xoshiro
Xoshiro is a family of fast, space-efficient and high quality PRNGs. It is considered the state-of-the-art (SOTA) family of non-cryptographic pseudo random number generators (PRNGs). The Rust crate rand_xoshiro (which is part of the popular Rust crate rand) has implementations of Xoshiro256Plus and Xoshiro256PlusPlus . Xoshiro256PlusPlus is a very good …
GitHub API
Python Bindings - ghapi¶
ghapi provides 100% always-updated coverage of the entire GitHub REST API by automatically converting the OpenAPI spec to a Pythonic API. ghapi is always up to date with the latest changes to GitHub APIs.
Hands on the Python Library pexpect
Tips and Traps¶
The command-line tool of some (e.g., network) applications might be slow to authenticate. If you use pexect to automate such a command-line tool, it is best to wait for sometime after sending password using
child.sendline(passwd)
. If the authentication has ouput on both success and failure, a smart way is to wait for the success or failure message to come out.