• January 3, 2021
  • January 3, 2021

Python: Output the log with logging module

It is general to export the log from the batch script which is executed periodically. The log is also useful to analyze the problem. You may insert the special log for debug to explore the reason of bug. The log is base facility to explore the reason of problem and recover from it. You can output the log from Python script with logging module. Simple Logging Most simple logging code is following. import logging logging.basicConfig(level=logging.INFO) logging.info("Most Simple Log. The Value is %d.", 10) Execute this script, the following log will be output. $ python3 demo.py INFO:root:Most Simple Log. The Value is […]

  • January 2, 2021
  • December 26, 2020

Python: Get the Command Line Argument with ArgumentParser

It is easy to get the command line argument of python shell script with ArgumentParser class. The ArgumentParser class has following functions: Get the positional required argument Get the optional argument Output the help If the script executed without required arguments, the ArgumentParser class abort the script. It is hard work to write above functions by yourself in your own script. Basic usage The basic code to use `ArgumentParser` class is following: import argparse # Allocate the parser parser = argparse.ArgumentParser() # Register arguments to the parser # Parse command line arguments # The result will be returned into the args variable. args […]

  • January 1, 2021
  • December 26, 2020

Creating the disk image file has HFS+ file system

The default file system of the macOS is changed to APFS since macOS High Sierra 10.13. The file system of the disk image file which is created by the Disk Utility had been changed to APFS also. They are not able to mount on earlier OS than macOS 10.13 which not supports APFS. This article how to create the disk image file with specify the file system. Creating the disk image file To create the disk image file, you can following way: Use the Disk Utility Use the hdiutil To specify the file system, use hdiutil to create the disk […]

  • December 31, 2020
  • December 26, 2020

Creating the zip file in format as same as Finder

Finder has a function create the zip file from the file or the folder. This zip file is different from the zip file Windows creates. This article says this zip file as Finder style zip file. You can create this zip file from the terminal and the shell script. You can create it in the automated script. This article explains that how to create the Finder style zip file and how to expand it. Creating the Finder style zip file You can create the Finder style zip file with ditto. $ ditto -c -k --sequesterRsrc --keepParent Test Test.zip Above line […]

>Programming Tips From Software Engineer

Programming Tips From Software Engineer

Technical News, Documents and Tips.