Book Image

Python Automation Cookbook - Second Edition

By : Jaime Buelta
Book Image

Python Automation Cookbook - Second Edition

By: Jaime Buelta

Overview of this book

In this updated and extended version of Python Automation Cookbook, each chapter now comprises the newest recipes and is revised to align with Python 3.8 and higher. The book includes three new chapters that focus on using Python for test automation, machine learning projects, and for working with messy data. This edition will enable you to develop a sharp understanding of the fundamentals required to automate business processes through real-world tasks, such as developing your first web scraping application, analyzing information to generate spreadsheet reports with graphs, and communicating with automatically generated emails. Once you grasp the basics, you will acquire the practical knowledge to create stunning graphs and charts using Matplotlib, generate rich graphics with relevant information, automate marketing campaigns, build machine learning projects, and execute debugging techniques. By the end of this book, you will be proficient in identifying monotonous tasks and resolving process inefficiencies to produce superior and reliable systems.
Table of Contents (16 chapters)
14
Other Books You May Enjoy
15
Index

To get the most out of this book

  • Before reading this book, readers need to know the basics of the Python language. We do not assume that the reader is an expert in the language.
  • The reader needs to know how to input commands in the command line (Terminal, Bash, or equivalent).
  • To understand the code in this book, you need a text editor, which will enable you to read and edit the code. You can use an IDE that supports the Python language, such as PyCharm and PyDev—which you choose is up to you. Check out this link for ideas about IDEs: https://realpython.com/python-ides-code-editors-guide/.

Download the example code files

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at http://www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the on-screen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Python-Automation-Cookbook-Second-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781800207080_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, object names, module names, folder names, filenames, file extensions, pathnames, dummy URLs and user input. Here is an example: "For this recipe, we need to import the requests module."

A block of code is set as follows:

   # IMPORTS
   from sale_log import SaleLog
   def get_logs_from_file(shop, log_filename):
   def main(log_dir, output_filename):
... 
   if __name__ == '__main__':
     # PARSE COMMAND LINE ARGUMENTS AND CALL main()

Note that code may be edited for concision and clarity. Refer to the full code when necessary, which is available at GitHub.

Any command-line input or output is written as follows (notice the $ symbol):

$ python execute_script.py parameters

Any input in the Python interpreter is written as follows (notice the >>> symbol):

>>> import delorean
>>> timestamp = delorean.utcnow().datetime.isoformat()

To enter inside the Python interpreter, call the python3 command with no parameters:

$ python3
Python 3.8.2 (default, Mar 11 2020, 00:28:52)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Verify that the Python interpreter is Python 3.8 or higher. It may be necessary to call python or python3.8, depending on your operating system and installation options. See Chapter 1, Let's Begin Our Automation Journey, specifically the Activating a virtual environment recipe—for further details about the use of different Python interpreters.

Bold: Indicates a new term, an important word, or words that you see on the screen, for example, in menus or dialog boxes. For example: "Select System info from the Administration panel."

Warnings or important notes appear like this.

Tips and tricks appear like this.