Lesson 13: Python Modules and Libraries

Watch the video above.

This key concepts lesson will be short as the video summarizes the details. For digital humanities projects in which you want to use Python, you will very likely need to use third-party modules. This is not considered plagiarism. This is not considered cheating. They are open source and free to use.

What are modules? They are blocks of code written by others, from academic institutions like M.I.T. and Stanford to Pythonistas. They allow you to use past work and bring complex functions into your own code. Each time you work with a module, get to know the functions, the arguments they take, and how they work. Most modules have good documentation that can be found on their main website. Simply Google the name of module and you can find the homepage of the module easily.

To install modules, you use the built-in Python installation module called Pip. You open command prompt and type pip install [module name] but without the brackets.

To import a module, you use the import operator. Simply write import [module name] without brackets in your Python script. You must import a module before you can use its functions. Most coders put all their imports at the top of the script. In more advanced machine learning projects, however, you do this as you code. For the purposes of this tutorial series, we always import our modules at the top of our script.

In Lesson 14: Coding Exercise, we do just this. We import re, or Regex. Once you are comfortable with this concept, feel free to move on to Lesson 14. You will get more comfortable with modules as you work through this series.