-
Book Overview & Buying
-
Table Of Contents
Python Automation Cookbook - Second Edition
By :
In a lot of automated tasks, we'll need to treat input text structured in a known format and extract the relevant information. For example, a spreadsheet may define a percentage in a piece of text (such as 37.4%) and we want to retrieve it in a numerical format to apply it later (0.374, as a float).
In this recipe, we'll learn how to process sale logs that contain inline information about a product, such as whether it has been sold, its price, profit made, and other information.
Imagine that we need to parse information stored in sales logs. We'll use a sales log with the following structure:
[<Timestamp in iso format>] - SALE - PRODUCT: <product id> - PRICE: $<price of the sale>
For example, a specific log may look like this:
[2018-05-05T10:58:41.504054] - SALE - PRODUCT: 1345 - PRICE: $09.99
Note that the price has a leading zero. All prices will...