Ben Chuanlong Du's Blog

It is never too late to learn.

The Walrus Operator in Python 3.8

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

List Comprehension

Notice that a walrus expression in a list comprehension must be in included in parentheses (to avoid ambiguitions).

The try/except/finally Block in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. The finally statements are guaranteed to be executed (presuming no power outage or anything outside of Python's control) after a try/except block runs even if return, break

Dataclass vs namedtuple in Python

Tips and Traps

  1. Prefer Dataclass to namedtuple for many reasons.

    • A namedtuple is immutable while a dataclass can be both mutable (frozen=False which is the default) or immutable (frozen=True).

      However, namedtuple does have one advantage over dataclass. Members of a namedtuple is assible both via the dot operator and index. In situations where both dot accessing and index accessing of members is required, a namedtuple comes handy. For examples, a list of namedtuple objects can be used as the data for creating a pandas DataFrame but not a list of dataclass objects.

Web Engines

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

webview

A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. The goal of the project is to create a common HTML5 UI abstraction layer for the …

Public Private Key Pair Implementations

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

  • SSH key pairs – encrypt and authenticate remote connections
  • PGP key pairs – encrypt e-mails, disks, arbitrary files to securely sign or delete them.
  • SSL key pairs – encrypt TCP/IP communications and secure …