View on GitHub

Code Fellows reading notes

A repository for organizing notes from my learning.

Automation in Python

Regex

Source: Datacamp - Python Regular Expression Tutorial

Regex is used for detecting patterns. In Python, this will involve importing the re library.

Defining regex patterns in Python is done with a raw string literal, such as r"potato".

Numbers and letters are the most simple characters that can be searched with regex, but there are others!

There are many more. Check the reading or regex101 for more.

Shutil

Source: pymotw.com - shutil

shutil is high-level file operation library for things like copying and archiving.

copyfile() copies the contents of a source to a destination.

copy() also copies, but interprets the output name like unix cp.

File metadata can be copied and transferred using copymode() and copystat()

copytree() can be used to copy entire directory trees. The destination directory must not exist before executing.

which() scans a path looking for a named file. If no match is found, returns None.

make_archive() creates a new archive file. Defaults to current directory, and executes recursively for all contents. root_dir and base_dir arguments can be used to change behavior.

unpack_archive() is used to extract files from an archive file.

disk_usage() returns a tuple with total space, amount in use, and amount remaining free.

All of these useful functions and methods can be used to manipulate and automate file operations on our machine!