Create and Modify PDF Files in Python
So far, you’ve learned how to extract text and pages from PDFs and how to concatenate and merge two or more PDF files. These are all common operations with PDF files, but pypdf has many other useful features. In the following sections, you’ll learn how to rotate and crop pages in a PDF file. Rotating Pages With PageObject.rotate() You’ll start by learning how to rotate pages. For this example, you’ll use the ugly.pdf file in the practice_files/ folder. This file […]
Read moreGetting the First Match From a Python List or Iterable
At some point in your Python journey, you may need to find the first item that matches a certain criterion in a Python iterable, such as a list or dictionary. The simplest case is that you need to confirm that a particular item exists in the iterable. For example, you want to find a name in a list of names or a substring inside a string. In these cases, you’re best off using the in operator. However, there are many […]
Read moreChoosing the Best Coding Font for Programming
When you’re coding, there’s always a font involved in displaying the text on the screen. Yet, the font that you use is an often-overlooked piece in your programming tool kit. Many operating systems and code editors come with their default monospace fonts that you may end up using. But there are a bunch of technicalities and features to take into consideration when choosing the best font for your daily programming. That’s why it’s worth investigating the requirements that a programming […]
Read moreChoosing a good file format for Pandas
Before you can process your data with Pandas, you need to load it (from disk or remote storage). There are plenty of data formats supported by Pandas, from CSV, to JSON, to Parquet, and many others as well. Which should you use? You don’t want loading the data to be slow, or use lots of memory: that’s pure overhead. Ideally you’d want a file format that’s fast, efficient, small, and broadly supported. You also want to make sure the loaded […]
Read morePython’s .__call__() Method: Creating Callable Instances
In Python, a callable is any object that you can call using a pair of parentheses and, optionally, a series of arguments. Functions, classes, and methods are all common examples of callables in Python. Besides these, you can also create custom classes that produce callable instances. To do this, you can add the .__call__() special method to your class. Instances of a class with a .__call__() method behave like functions, providing a flexible and handy way to add functionality to […]
Read more