Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Debug Python Project in Visual Studio Code

Ways to Open a Command Palette

  1. Use Menu Menu -> View -> Command Palette....
  2. Use the shortcut Shift + Command + P (on macOS).

Command Palette

You can search for commands in the Command Palette, which makes things very convenient.

Run Tests or a Python File

  1. Open the Command Palette.
  2. Search for Python: Run in the …

Static Type Checking of Python Scripts Using pytype

Configuration

There are 3 ways to control the behavior of `pytype.

  1. Pass command-line options to pytype.

  2. Specify a configuration file using pytype --config /path/to/config/file .... You can generate an example configuration file using the command pytype --generate-config pytype.cfg.

  3. If no configuration file is found, pytype uses the …

Call Java Using PyJNIus from Python

PyJNIus is a simple-to-use Java interface for Python. However, JPype is a better alternative.

Installation

pip install Cython
pip install pyjnius

Example with Imported Jar

import os
os.environ["CLASSPATH"] = "/path/to/your.jar"
from jnius import autoclass
YourClass = autoclass(path.to.YourClass)
yourObj = YourClass()

Note: Avoid using the same …

Avoid Database Lock in SQLite3

  1. According to https://www.sqlite.org/lockingv3.html, POSIX advisory locking is known to be buggy or even unimplemented on many NFS implementations (including recent versions of Mac OS X) and that there are reports of locking problems for network filesystems under Windows. So, the rule of thumb is to …

Work with Long Strings in Python

This article discusses different ways to write long strings in Python.

Long String in One Line

A long string can be put on the the same line, which is ugly of course.