Blogs

Advertisement

Advertisement

Python MySQL Tutorial

MySQL is an ubiquitous database server. Many hosts, like Interserver.net offer unlimited MySQL databases with a $4/month plan. With their hosting, you can also setup as many PHP, Python, Ruby, or Node.js apps.

There are a few libraries available, but the one I'm focusing on is PyMySQL, a pure Python implementation. This version is the easiest to install with the least amount of dependencies and most portable.

You could use an ORM like SQLAlchemy or Django. Those options are good if you need to easily switch between MySQL and another database like SQLite. Here, we will focus only on MySQL and assume this is the only database being used.

If you're interested in learning how to setup a Python web app on Interserver, it is really easy using cPanel. Check out my tutorial Setup Python WSGI apps on cPanel (Flask/Django).

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.

Advertisement

Advertisement