Difference between revisions of "Python Resources"
m |
|||
Line 1: | Line 1: | ||
I've reviewed these resources and highly recommend them. I periodically update this page, but it may be out of date. | |||
==Learning Python== | ==Learning Python== | ||
You need to be able to run Python programs. You have three options: | |||
# Although Python is pre-installed on many computers, you should download and install [https://www.anaconda.com/ the Anaconda Python distribution]. It has all of the packages you need. | |||
# Alternatively, you can learn it entirely using web-based Jupyter notebooks. | |||
===If you don't know how to program=== | ===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: | If you have never programmed with Python before, you may want to start with DataCamp's Learn python by example: | ||
* https://www.learnpython.org, powered by DataCamp. For example, look at the [https://www.learnpython.org/en/String_Formatting String Formatting] lesson | * https://www.learnpython.org, powered by DataCamp. For example, look at the [https://www.learnpython.org/en/String_Formatting String Formatting] lesson | ||
I also recommend: | |||
* [https://www.diveinto.org/python3/ Dive Into Python 3] (book, online for free; a little dated.) | * [https://www.diveinto.org/python3/ Dive Into Python 3] (book, online for free; a little dated.) | ||
* [https://wiki.python.org/moin/BeginnersGuide/NonProgrammers Python for Non-Programmers] | * [https://wiki.python.org/moin/BeginnersGuide/NonProgrammers Python for Non-Programmers] | ||
===If you know how to program=== | ===If you know how to program=== | ||
If you know another programming language (e.g. C, C++, FORTRAN | 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: | Start by reading the Python Tutorial: | ||
Line 63: | Line 69: | ||
* http://www.cc.gatech.edu/classes/AY2013/cs1301_summer/presentations/calico_graphics.pdf | * http://www.cc.gatech.edu/classes/AY2013/cs1301_summer/presentations/calico_graphics.pdf | ||
===Games=== | ===Writing Games=== | ||
* http://www.pygame.org/ pygame - a Python game development system | * http://www.pygame.org/ pygame - a Python game development system | ||
* [http://peak.telecommunity.com/DevCenter/EasyInstall PEAK Easy Install] | * [http://peak.telecommunity.com/DevCenter/EasyInstall PEAK Easy Install] | ||
Line 88: | Line 94: | ||
* pyqt - Use PyQT5 (it's part of Anaconda) | * pyqt - Use PyQT5 (it's part of Anaconda) | ||
* [http://www.fltk.org/ FLTK], the Fast Light Toolkit | * [http://www.fltk.org/ FLTK], the Fast Light Toolkit | ||
However, I strongly recommend writing your python program as a web-based app (see next section) | |||
==Building Web Applications== | ==Building Web Applications== | ||
Line 131: | Line 140: | ||
==Python Installation== | ==Python Installation== | ||
=Advanced Python= | =Advanced Python= |
Revision as of 08:01, 25 April 2020
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:
- 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.
- 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:
- https://www.learnpython.org, powered by DataCamp. For example, look at the String Formatting lesson
I also recommend:
- Dive Into Python 3 (book, online for free; a little dated.)
- Python for Non-Programmers
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:
- Official Python Documentation. Just read the documentation. Honestly. It's well-written.
- Python Tips (book, online for free)
- Python Google Style Guide.
Using Python
Recommended packages and tools for different tasks
Developer Tools
- PyCharm
- Jupyter Notebook
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
String Formatting
- https://pyformat.info --- Big how-to on using the % and .format() formatting
Image Manipulation
- Use Pillow, the Python2/3 fork of Python Image Library (PIL).
Fun examples:
- http://jeremykun.com/2012/01/01/random-psychedelic-art/
- http://pythonvision.org/basic-tutorial
- http://stackoverflow.com/questions/138250/read-the-rgb-value-of-a-given-pixel-in-python-programatically
Text Processing
Graphing
- matplotlib - a handy system for plotting in python. (Short example of using matplotlib within jupyter)
- holoview
- Altair: Declarative Visualization in Python
- geopy - geocoding for Python
- Seaborn. (See Datacamp Tutorial)
Easy Graphics
- Graphics.py: http://mcsp.wartburg.edu/zelle/python/graphics.py http://mcsp.wartburg.edu/zelle/python/ http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf
- HTML graphics: http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/graphics.html
- http://plotdevice.io/
- http://www.cc.gatech.edu/classes/AY2013/cs1301_summer/presentations/calico_graphics.pdf
Writing Games
- http://www.pygame.org/ pygame - a Python game development system
- PEAK Easy Install
- Crystal Space 3D
- VPython 3D Programming in Python
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:
- See also https://wiki.python.org/moin/WebFrameworks
- https://github.com/MichaelPereira/webhooks-demo-application
- https://mattcarrier.com/flask-dreamhost-setup/
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 wsgi_app.py
Using Passengers on Dreamhost:
- https://www.byteconsole.com/get-flask-up-and-running-on-a-dreamhost-server-with-passenger/
- https://help.dreamhost.com/hc/en-us/articles/215769578-Passenger-overview
- https://help.dreamhost.com/hc/en-us/articles/216137717-Python-overview
- https://help.dreamhost.com/hc/en-us/articles/115000218612-Installing-a-custom-version-of-Python
- https://help.dreamhost.com/hc/en-us/articles/115000702772-Installing-a-custom-version-of-Python-3
- https://help.dreamhost.com/hc/en-us/articles/215489338-Installing-virtualenv-and-custom-modules-in-Python
- https://help.dreamhost.com/hc/en-us/articles/115000221112-Using-pip-to-install-Python-modules
Good Tutorials
Writing a full application with Apache, Bottle and MongoDB:
Python Installation
Advanced Python
- Fluent Python: Clear, Concise, and Effective Programming (you can get it on Safari)