Ben Chuanlong Du's Blog

It is never too late to learn.

Tips on PyPy

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

Installation

  1. Download PyPy from https://www.pypy.org/download.html.

  2. Unzip it.

  3. Install pip.

    :::bash /path/to/pypy -m ensurepip /path/to/pypy -m pip install ...

Packages Failed to Install

pytype …

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

Exception and Error Handling in Python

Tips and Traps

  1. If you need trackback information when throwing an exception use raise ExceptionClass(msg), otherwise, use sys.exit(msg) instead.

  2. The assert statement (which raises AssertionError if the assertion is not met) is a very good way to ensure conditions to be met.

     :::python
     assert some_condition