Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Hands on the Python module subprocess

General Tips

  1. The method subprocess.run is preferred over older high-level APIs (subprocess.call, subprocess.check_call and subprocess.check_output). The method subprocess.Popen (which powers the high-level APIs) can be used if you need advanced controls. When running a shell command using subprocess.run,

    1. Avoid using system shell (i.e., avoid using shell=True) for 2 reasons. First, avoid shell injection attack. Second, there is no need for you to manually escape special characters in the command.

Managing Virtual Environments in Poetry

Where to Create Virtual Environments

By default, Poetry create virtual environment in $HOME/.poetry for cahcing/sharing purpose. However, it is inconvenient if you use Docker-based web IDE for a Python project as you will lose the created virtual environment once the Docker container is restarted. In that situation, you …

Special Characters to Avoid in Strings

This articles talks about special characters to avoid in various places. You might not encounter issues most of the time when violating rules stated below, however, you never know when things will break. It is more for a good-practice suggestion.

String for Shell

  1. When you pass parameters from one program …

Useful Plugins for Eclipse

Terminal Plug-in

"Terminal Plug-in" is a fully-working command-line terminal for Eclipse.

EasyShell

"EasyShell" allows to open a shell window or file manager from the popup menu in the navigation tree or editor view.

Vrapper

Vrapper provides Vim-like scheme for Eclispe. You can edit code similar as what you do in …

Advanced Use of "head" and "tail"

It is suggested that you use Python instead of Shell to manipulate text files!!

Besides passing an unsigned integer as parameter to the option -n, you can also pass a signed integer to it. When a signed integer is passed to -n, it means from/to (inclusive/exclusive similar to …