NanoDano's blog



How to format an SD card or USB flash drive

If you want to create a bootable SD card or USB flash drive using a disk image like a .iso or .img you have a few options.

  • Use the dd command-line tool
  • Use a GUI tool like BalenaEtcher

This is a common task when setting up an SD card for a Raspberry Pi or creating a USB flash drive with a Linux LiveCD distro. In this example we will review both the Etcher option and dd option.

Python SQLite3 Tutorial

Python has a built-in Sqlite3 module named sqlite3. This module allows you to create, connect, and modify SQLite 3 databases.

To learn more about SQLite3 and how to use it in general, check out my SQLite3 Tutorial and my other sqlite tutorials.

If you need a database-agnostic library, something that you can use with SQLite and then easily configure to start using MySQL without rewriting all of your code, you want to use an ORM. ORM stands for Object-Relational-Mapping and the most popular one for Python is SQLAlchemy and Django's ORM.

Using stdin, stdout, and stderr in Python

Among the popular operating systems, they have all standardized on using standard input, standard output, and standard error with file desciptors 0, 1, and 2 respectively. This allows you to pipe the inputs and outputs to different locations. Let's look at how to utilize standard input, output, and error in Python.

To learn more about piping, redirection, stdin, stdout, and stderr in general, see my tutorial STDIN, STDOUT, STDERR, Piping, and Redirecting.

Taking Command Line Arguments in Python

When processing command line arguments in Python, you have a few options available:

  • sys.argv - a raw list of arguments passed to the Python interpreter
  • argparse - Python's standard package for argument parsing (replaces getopt and optparse)
  • fileinput.input() - A special function, similar to Ruby's ARGF, that returns the lines of input from standard input or from the list of filenames provided as arguments.
  • docopt - A third-party package that uses the docstring as documentation and configuration for arg parsing
  • click - A third-party package that uses decorators to map command arguments

Let's look at examples of each option.