Python
Introduction
This module is designed to introduce you to the programming language Python. We will:
- explore why Python is so widely used
- introduce the user interfaces IDLE and Jupyter Notebooks
- familiarise ourselves with the coding language
- learn how to open a .txt file and find all instances of a word
- learn some basic manipulations of tables
- learn how to save the edited files
- Download Python. Make sure during the install you go to ‘Customize installation’ and ensure ‘PIP’ and ‘IDLE’ are included as part of the installation. Once downloaded, type ‘IDLE’ into your computer’s searchbar. You should see a result of ‘IDLE(Python 3.7 64-bit)’ (or the bit version you chose). Click it, and if you see a white box with ‘»>’, it works.
- Download 2.1_Python_scripts_data.zip and extract the files. Make sure they are all in the same folder on your computer.
- OPTIONAL: Install Pandas package on your computer: press your windows button on your keyboard and the r key. You will see a small window asking what yu want to run. Make sure the drop-down manu has ‘cmd’ selected, and click ‘OK’. Type ‘pip install pandas’, and press enter. You should see a line saying it is complete and these are now installed.
If there are any issues with these tasks, please send an email to Ellie (eleanor.bennett@helsinki.fi).
- Python version 3.9. It is important we all use the same version, as certain commands are different depending on the version of Python. The important thing is you’ve downloaded Python version 3, NOT Python version 2.
You can also install the software during the ‘application dropin’ slot on Monday 01.08.2022.
- Short lecture (also available as a pdf) explaining what Python is, introducing IDLE and Jupyter Notebooks, and how Python is used in digital humanities.
- Classic ‘Hello, world!’ exercise. We will learn the difference between intergers and strings, the importance of defining entities, and the command ‘print’. We will also learn how to save a piece of Python code.
- Open, read, and find all instances of words in a .txt file. You will be introduced to packages. We will open a sample .txt file using Python. We will learn the difference between ‘opening’ and ‘reading’ a file in Python. You will then be introduced to Regular Expressions (Regex), which will be used to search for all instances of a specific word.
- Run your own basic statistical analysis on the example text.
- Introduction to code that will allow you to manipulate .csv files.
Python is widely used, so there are many tutorials and guides and available for free. If you would like to use Python in the future, I recommend shopping around to see which guides suit your learning style best. Below is a short list of the resources that have helped Ellie.