For the past few years, many librarians have included coding activities in their curriculum. Yet most librarians themselves do not know how to code. They might feel as though they do not have time to learn something new. They might be intimidated by computer science. Or maybe they feel like they are all thumbs when it comes to technology. The good news is that one does not have to be a genius to learn a few coding shortcuts with Python that will make their job easier.
How Can Python Be Used in a Library?
Python is a powerful programming language that is easy to learn and can be used to simplify repetitive tasks. There are several ways that librarians can use Python: automate social media accounts, remove missing or duplicated data from your ChalkDust statistics spreadsheet, or create virtual booktalks. Let’s explore a few functions for Python and some resources for curious librarians who want to know more about Python.
Using Python to Convert Text to Speech
Recently, while working on a virtual booktalk project, I wanted to use a text-to-speech (TTS) converter, because I do not like the way my voice sounds when recorded. For a variety of reasons, none of the websites I found fit my requirements (free and ongoing in comparison to paid or freemium). Then, I realized that I had the skills to make my own converter using Python. Even better – someone had already created one! I just needed to copy the code and tweak a couple of variables before I had exactly what I needed. A few minutes later, I had a program that allowed me to input a bit of text and then convert that text into speech, saving it to an mp3 file. The only cost involved was about ten minutes of my time, and I can reuse the converter any time I need.
Using Python to Automate Tweets
Another timesaving use for Python is to automate your library’s Twitter account. With a few lines of code, you can set your Twitter account to send out tweets at whatever time interval you want – one hour, two hours, or thirty-six hours. The hardest part about this process is actually not the code. As a matter of fact, much like the text-to-speech converter I mentioned earlier, the code for setting up and automating your Twitter account can be found with a simple search. Most of your time and effort will actually go into completing the necessary form and getting the key codes from Twitter.
Using Python with Spreadsheets
When working with spreadsheets, I can compare two or more Excel files for differences, and then record the differences into a .txt file that I can share with others. In addition, I can use Python to clean up missing or duplicated records from hundreds of entries in a spreadsheet. I only have to write the code once. Then, anytime I want to compare files or clean up some data, all I have to do is type in one command to run the program.
Python as a Password Generator
For those who are concerned about privacy and Internet security, once you are comfortable with Python, try making a password generator that lets the user change parameters, like how many characters to use for the password, whether to include special symbols, or whether to include a specific number of random words like the password appearing in the XKCD comic above. Of course, there are already some tools that create random passwords, but there is always the possibility that those tools also record the passwords that they generate. To be honest, nothing connected to the Internet is 100% safe. With my own program, I worry less about my passwords being recorded.
Resources for Beginners
If you would like to get started with Python to automate basic tasks, the following is a list of resources for beginners. I recommend starting with “Automate the Boring Stuff” by Al Sweigert and “Python Crash Course” by Eric Matthes. There are many other tutorials and videos on Python projects all over the Internet. YouTube is a treasure chest for finding tutorials that will walk you through projects step by step, and videos are a great way to get started because they can be paused and replayed when needed. Keep in mind, however, that there is no right or wrong way to learn how to code. Find whatever method works best for you.
“Automate the Boring Stuff with Python” by Al Sweigart. (free)
Al Sweigert provides free access to digital copies of all his books through his website. “Automate the Boring Stuff with Python” has both step-by-step instructions and practice projects. Sweigert also offers free print copies to anyone who wants to write a review for one of his books. This book is great for those who would rather take what they need than read the book from cover to cover.
“Python Crash Course: 2nd Edition” by Eric Matthes ($39.95 print; $31.95 Ebook)
“Python Crash Course” complements the information covered in Sweigart’s “Automate the Boring Stuff with Python.” This book is divided into two parts, with the first section covering basic Python. The second part contains three sections: a video game, data visualization, and web applications. These sections highlight the versatility of Python. Readers can skip around or read from front to back.
- Al Sweigart’s Automate the Boring Stuff
- Python Software Foundation – Python for Beginners
- Learn Python – A website that covers basic Python concepts
- Google’s Python Course
- Python Programming Playlist from Codemy
- Learn Python Programming Step-by-Step Playlist from Python Simplified
A repository for librarians of Python programs I have created to make my job easier. Hopefully, it will do the same for you!
Are you interested in learning even more about how to use Python to automate tasks in our library? Join Monica as she walks you through step-by-step Twitter automation with Python at TCEA 2023. No coding experience is required. Register before January 10 to get the $50 advanced pricing discount!
Thanks for the blog.