Generate a Simple PDF using Python ReportLab (9 Steps)

Problem Formulation and Solution Overview This article shows how to generate a formatted PDF file from a CSV file using the ReportLab and Pandas libraries in conjunction with slicing. ℹ️ Python offers numerous ways to generate a PDF file. One option is to use the ReportLab library. The article selected the path that used the … Read more

How to Write to a Binary File in Python?

Problem Formulation πŸ’¬ Question: Given a binary string in your Python script, such as b’this is a binary string’. How to write the binary string to a file in Python? For example, you may have tried a code snippet like this that will not work with file.write(): Because this yields a TypeError: Traceback (most recent … Read more

How to Write a Hex String as Binary Data & Binary File in Python?

Hex String as Binary Data To convert a hex string such as ‘FF0001AF’ to binary data, use the binascii.unhexlify(hex_str) function that returns the binary data represented by the hexadecimal string. Note that this converts two hex string digits to one byte, i.e., hex string ‘F0’ is converted to the byte representation 11110000, or in binary … Read more

How to Import External Code in Python

Problem Formulation and Solution Overview This article will show you how to import external Python code and use this code in another Python script. To make it more interesting, we have the following running scenario: πŸ‘©β€πŸ« Fun Example: Pam, a High School Teacher, wants an easier way to calculate exam totals and produce student averages. … Read more

How to Read the First Line of a File in Python

Problem Formulation and Solution Overview This article will show you how to read and display the first line of a file in Python. For this article, we will work with a flat-text file containing five (5) possible things to do during your lifetime. This file is saved to bucket_list.txt and placed into the current working … Read more

How to Change File Permissions in Python?

Problem Formulation and Solution Overview When a new file or folder is created, it comes with its own set of default permissions. From time to time, you will need to adjust these permissions. To follow this article, download the finxter.csv file and move this file to the current working directory. What are File Permissions? File … Read more