Python Resources

From Simson Garfinkel
Revision as of 09:52, 25 April 2020 by Simson (talk | contribs) (→‎Financial Modeling)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I've reviewed these resources and highly recommend them. I periodically update this page, but it may be out of date.

Learning Python

You need to be able to run Python programs. You have three options:

  1. Although Python is pre-installed on many computers, you should download and install the Anaconda Python distribution. It has all of the packages you need.
  2. Alternatively, you can learn it entirely using web-based Jupyter notebooks.

If you don't know how to program

If you have never programmed with Python before, you may want to start with DataCamp's Learn python by example:

I also recommend:

If you know how to program

If you know another programming language (e.g. C, C++, FORTRAN, Java, etc.), you can learn Python in about 2 hours.

Start by reading the Python Tutorial:

I then recommend reading the documentation:

Using Python

Recommended packages and tools for different tasks

Developer Tools

Financial Modeling

Nice blog entries:

Some books:

Numerical Data Processing

  • numpy - numeric analysis in python (needed for matplotlib)
  • pandas or SparkSQL
  • tabulate - create tables easily (but see my tytable replacement)

Date Data

  • dateutil, included in the Anaconda distribution
  • iCalendar, package for Python, generates calendears

String Formatting

Image Manipulation

  • Use Pillow, the Python2/3 fork of Python Image Library (PIL).

Fun examples:

Text Processing

See Text processing notes.


Easy Graphics

Writing Games

Database Access

Python contains built-in support for SQLite3.

For using MySQL, you'll need a connector. There are many available.

Install MySQL connector on anaconda:

   conda install mysql-connector-python

Then you can:

   import mysql.connector as mysql
   c = mysql.connect(host=host,database=db,user=user,password=password)

I generally prefer PyMySQL, as it's pure-python and has fewer dependencies.

Python GUI Options

I need to write some programs that use GUI.

  • pyqt - Use PyQT5 (it's part of Anaconda)
  • FLTK, the Fast Light Toolkit

However, I strongly recommend writing your python program as a web-based app (see next section)

Building Web Applications

You basically have two options:

  • Write a CGI script (slow, but easy. Don't use for more than 1 request every 10 seconds)
  • Some sort of Web Server Gateway Interface (WSGI). Options include:
    • Bottle (easy, and the whole thing runs from a single file)
    • Flask (can run on Apache with Passenger, but needs its own domain name)
    • Writing your own (don't do this.)

The WSGI server needs to be run from a program that receives the Port80 connections. The two ways I've done this are:

  • mod_wsgi running within Apache. (This works surprisingly well and allows you to run bottle or flask side-by-side other systems)
  • CherryPy (Includes its own web server and will hand off to Bottle or Flas.)

For more information, see:

If you are using anything other CGI, you need some way to tell the web server to reload your python program. (You don't need to do this with CGI---it reloads Python and your program every time you serve another request. That's why it's so slow...)

To reload your program on Dreamhost with passenger:

   $ touch tmp/restart.txt         # reload your program

To reload your program with mod_wsgi:

   $ touch 

Using Passengers on Dreamhost:

Good Tutorials

Writing a full application with Apache, Bottle and MongoDB:

Advanced Python