Ben Chuanlong Du's Blog

It is never too late to learn.

Class in Python

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

@abstractmethod, @staticmethod, abstract class, etc.

override,

prefer classmethod to static method;

both class and static methods can be override

Meta Class

https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python

It seems to me …

Schdule Jobs in Python

Tips and Traps

  1. If you schedule a job $J_1$ using schedule in IPython shell, and then interrupt the following loop that checks and runs pending jobs,
    while True:
         schedule.run_pending()
    
    the scheduled job $J_1$ is still there unless you stop the current IPython shell. The effective consequence of this is that if you schedule another job $J_2$, and start to run it using the following loop,

The Installation Location of Python Packages Using Pip

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

When installing a Python package using pip without using sudo or the root user, the package is installed into the user's local directory at ~/.local/lib/python3.7/site-packages (using Python …

Take Screenshots in Python

Comments

  1. PIL.ImageGrab works on macOS and Windows only.
  1. PIL.ImageGrab is relatively slow. python-mss and PyQt5 are better alternatives if performance of screenshot is critical. Notice that saving an (e.g., PNG) image can take significant time (might take up to 0.5 seconds) too, this is often due to image compression is slow. Lower the compression level can significant reduce the time needed to save an image. Please refer to Saving a PNG file is slow