CDH-cookbook

Milestone Lesson 1: Your First Program

^ Main contents

Contents

Summary of Material Covered So Far

At this point, you have seen three lessons covering the most fundamental concepts and foundational skills for coding in Python. You have also had the opportunity to complete exercises which teach you to navigate the language and lightly process some data.

Here is a list of the topics we have covered so far:

In lesson 1 you learned about the nature of ‘coding’:

In lesson 2 we discussed getting your coding environment set up, and some features of the Python language and data that one must know in order to code:

In Lesson 3 we introduced the essential element of Python code, the function:

Coding, however, is a skill. Here is a checklist of the skills you need to confidently proceed to the next lessons:

Back to table of contents

Why Did I Learn This?

At this stage you may be asking yourself ‘So what? How does declaring a variable or knowing that functions begin with ‘def’ help me actually accomplish my research objectives?’ At this stage many Humanities researchers often feel disconnected from their actual goals and find that they are not concerned so much with the finer points of coding; their primary aim is a research output. Many people find themselves tuning out from tutorials and lessons after learning these basics because they feel that these concepts do not directly apply to their goals. This is a common frustration for Humanities researchers who know that they need to have some coding knowledge but also simply want to begin benefitting from the power of code.

The way to remedy this disconnect is to better understand what the concepts you have learned enable you to achieve right now. Remember, code is a tool, and to learn to code is to gain the skills needed to wield that tool. Let’s break it down more directly:

  1. Understanding the boring details of how to install and load Python modules, how to click through cells in a Jupyter Notebook, or what is a variable, are absolutely fundamental concepts one must have in order to do anything with Python code. What you have learned so far are not arbitrary details but instead are the foundation necessary to achieve results.
  2. You now know that various modules exist in Python’s module collection which can help you navigate data more effectively. You also know that all Humanities research involves data, even if you are working only with straightforward texts and the concepts those texts contain. But even more importantly, you have been introduced to code repositories, where researchers, many who work in or adjacent to the Humanities, publish their innovative code and methods. It is highly likely that someone out there has written code that you could begin using today which directly impacts your research. You are equipped with the knowledge to search for it and begin to read it.

However, let’s bring this into the realm of concrete application. In fact, learning these three things:

enables you to do something very powerful. At the heart of almost any Humanities research involving code is reading and analysing multiple files. Consider this question: if you needed to open, read, and change data in some files, and you have 30 texts to study, how would you do it manually? You would open the file, read it, make changes or record your notes somewhere, and close the file. You would repeat this 30 times. It would probably take you quite a while.

This, process however, is actually a for loop! You are iterating through your files and performing the same (or similar) things for each file. This can be translated into code, and then achieved at a much faster rate than if you were doing it by hand. For example, if your 30 texts are student-written essays, and you want to find data in each essay and copy-paste that data into a spreadsheet. You have now learned the skills to write a loop of code that will do this:

  1. Open a file.
  2. Find the specific data.
  3. Copy that data.
  4. Paste that data into a spreadsheet.
  5. Close the file.
  6. Repeat for each of your 30 essays.

This program would automate a task that would perhaps waste time if attempted manually. This convenience puts you ahead of many others who opt to do this the hard way by hand.

By extension, say you have a more advanced textual analysis technique that you want to employ to study these essays further - you will still need to be able to iterate through the texts, as well as know enough code to understand the basics of how to apply the technique itself. These skills again apply here. This should reassure you that studying these basics indeed is a step towards your goals.

The homework for this lesson is to follow a tutorial which helps you put your newfound skills together to write this program. You are encouraged to engage with it because it will help you understand how impactful a few simple coding concepts can be for your research.

In short, almost nothing one learns about coding is actually disconnected from real-world objectives, but it is easy to get lost in the details and lose sight of the bigger picture. Reminding yourself that there are concrete applications for everything you learn about code is the way to help keep your perspective and keep up your motivation to learn.

Back to table of contents

Should I Continue?

The previous three lessons covered the fundamentals of coding in Python. There are two points to consider before going forward. First, what are your objectives? If you simply need to slightly manipulate files and nothing more, it is likely that completing the homework tutorial for this lesson is sufficient for you to have an arsenal of necessary tools to carry forward. Your learning is by no means complete, but it can be directed by practical experience. However, if you want to do more complex things with your research, such as carry out different kinds of analyses, produce images and charts, link to databases or scrape internet data, or more – then you should continue to the end of this course.

Second, are you actually ready? The next lessons are more complex in concept and application. Check the list at the beginning of this lesson and ask yourself if you are confident with each of these items. Then, work through the homework tutorial and build your first program using a loop to iterate through some files on your computer. If you can build your first program with that tutorial, then you are ready to continue to the next few lessons.

Back to table of contents

Written by Estara Arrant, 2025-04-16
Licence: CC BY-SA 4.0

< Previous lesson | Next lesson >