Advanced Python
Modules
Complete Python Bootcamp
● Python has several built-in modules that
we haven’t fully explored yet!
● In this section we will dive deeper into
some useful built-in modules, explore their
use cases, and then give you a puzzle
exercise to solve.
Complete Python Bootcamp
● Modules Covered
● Collections
● Os module and Datetime
● Math and Random
● Python Debugger
● Timeit
● Regular Expressions
● Unzipping and Zipping Modules
Complete Python Bootcamp
● Let’s get started!
Collections Module
Shutil and OS
Modules
Opening and Reading Files and Folders
Complete Python Bootcamp
● We already know how to open an individual
file with Python, but we still don’t know
how to do a few things:
○ What if we have to open every file in
a directory?
○ What if we want to actually move files
around on our computer?
Complete Python Bootcamp
● Python’s os module and shutil allow us to
easily navigate files and directories on the
computer and then perform actions on
them, such as moving them or deleting
them.
● Let’s get started!
Datetime Module
Math and Random
Modules
Python Debugger
Complete Python Bootcamp
● When trying to figure out what errors there
are in your code, you’ve probably used
print() to try to track down the error.
● Fortunately, Python comes with a built-in
debugger tool that allows you to
interactively explore variables within mid-
operation of your Python code!
Regular Expressions
Part One
Complete Python Bootcamp
● We already know we can search for
substrings within a larger string with the in
operator:
○ “dog” in “my dog is great”
■ True
Complete Python Bootcamp
● This has severe limitations, we need to
know the exact string, and need to
perform additional operations to account
for capitalization and punctuation.
● What if we only the pattern structure of the
string we’re looking for? Like an email or
phone number?
Complete Python Bootcamp
● Regular Expressions (regex) allow us to
search for general patterns in text data!
● For example, a simple email format can be:
○ user@[Link]
● We know in this case we’re looking for a
pattern “text” + “@” + “text” + “.com”
Complete Python Bootcamp
● Regular Expressions (regex) allow us to
search for general patterns in text data!
● For example, a simple email format can be:
○ user@[Link]
● We know in this case we’re looking for a
pattern “text” + “@” + “text” + “.com”
Complete Python Bootcamp
● Regular Expressions (regex) allow us to
search for general patterns in text data!
● For example, a simple email format can be:
○ user@[Link]
● We know in this case we’re looking for a
pattern “text” + “@” + “text” + “.com”
Complete Python Bootcamp
● The re library allows us to create
specialized pattern strings and then search
for matches within text.
● The primary skill set for regex is
understanding the special syntax for these
pattern strings.
Complete Python Bootcamp
● Don’t feel like you need to memorize these
patterns! Focus on understanding how to
look up the information.
● Phone Number
○ (555)-555-5555
● Regex Pattern
○ r”(\d\d\d)-\d\d\d-\d\d\d\d”
Complete Python Bootcamp
● Don’t feel like you need to memorize these
patterns! Focus on understanding how to
look up the information.
● Phone Number
○ (555)-555-5555
● Regex Pattern
○ r”(\d\d\d)-\d\d\d-\d\d\d\d”
Complete Python Bootcamp
● Don’t feel like you need to memorize these
patterns! Focus on understanding how to
look up the information.
● Phone Number
○ (555)-555-5555
● Regex Pattern
○ r”(\d\d\d)-\d\d\d-\d\d\d\d”
Complete Python Bootcamp
● Don’t feel like you need to memorize these
patterns! Focus on understanding how to
look up the information.
● Phone Number
○ (555)-555-5555
● Regex Pattern
○ r”(\d\d\d)-\d\d\d-\d\d\d\d”
Complete Python Bootcamp
● Don’t feel like you need to memorize these
patterns! Focus on understanding how to
look up the information.
● Phone Number
○ (555)-555-5555
● Regex Pattern
○ r”(\d{3})-\d{3}-\d{4}”
Complete Python Bootcamp
● This series of lectures will first focus on
how to use the re library to search for
patterns within text.
● Afterwards we will focus on understanding
the regex syntax codes.
● Let’s get started!
Regular Expressions
Part Two
Timing Your Code
Regular Expressions
Part Two
Regular Expressions
Part Three
Timing Your Code
Complete Python Bootcamp
● As you learn more Python, you will
discover multiple solutions for a single task
and you may find yourself trying to figure
out the most efficient approach.
● An easy way to do this is to time your
code’s performance.
Complete Python Bootcamp
● We will focus on 3 ways of doing this:
○ Simply tracking time elapsed
○ Using the timeit module
○ Special %%timeit “magic” for Jupyter
Notebooks
Unzipping and
Zipping Files
Advanced Modules
Exercise Puzzle
SOLUTION