Book Read Free

Automate the Boring Stuff with Python

Page 53

by Al Sweigart


  backslash vs. forward slash, Files and File Paths

  current working directory, The Current Working Directory

  overview, Reading and Writing Files

  os.path module, The os.path Module, The os.path Module, The os.path Module, Handling Absolute and Relative Paths, Handling Absolute and Relative Paths, Finding File Sizes and Folder Contents

  absolute paths in, The os.path Module

  file sizes, Handling Absolute and Relative Paths

  folder contents, Handling Absolute and Relative Paths

  overview, The os.path Module

  path validity, Finding File Sizes and Folder Contents

  relative paths in, The os.path Module

  PAUSE variable, Pauses and Fail-Safes, Step 2: Set Up Coordinates

  PdfFileReader objects, Extracting Text from PDFs

  PDF files, Working with PDF and word Documents, PDF Documents, Extracting Text from PDFs, Decrypting PDFs, Creating PDFs, Copying Pages, Overlaying Pages, Overlaying Pages, Encrypting PDFs, Encrypting PDFs, Encrypting PDFs, Step 1: Find All PDF Files, Step 1: Find All PDF Files, Step 2: Open Each PDF

  combining pages from multiple files, Encrypting PDFs, Encrypting PDFs, Encrypting PDFs, Step 1: Find All PDF Files, Step 1: Find All PDF Files, Step 2: Open Each PDF

  adding pages, Encrypting PDFs

  finding PDF files, Step 1: Find All PDF Files

  opening PDFs, Step 1: Find All PDF Files

  overview, Encrypting PDFs

  saving results, Step 2: Open Each PDF

  creating, Decrypting PDFs

  decrypting, Extracting Text from PDFs

  encrypting, Overlaying Pages

  extracting text from, PDF Documents

  format overview, Working with PDF and word Documents

  pages in, Creating PDFs, Copying Pages, Overlaying Pages

  copying, Creating PDFs

  overlaying, Overlaying Pages

  rotating, Copying Pages

  PdfFileWriter objects, Decrypting PDFs

  pformat() function, The setdefault() Method, Saving Variables with the shelve Module

  overview, The setdefault() Method, Saving Variables with the shelve Module

  saving variables in text files using, Saving Variables with the shelve Module

  phone numbers, extracting, Combining re.IGNORECASE, re.DOTALL, and re.VERBOSE, Combining re.IGNORECASE, re.DOTALL, and re.VERBOSE, Project: Phone Number and Email Address Extractor, Step 2: Create a Regex for Email Addresses, Step 3: Find All Matches in the Clipboard Text

  creating regex, Project: Phone Number and Email Address Extractor

  finding matches on clipboard, Step 2: Create a Regex for Email Addresses

  joining matches into a string, Step 3: Find All Matches in the Clipboard Text

  overview, Combining re.IGNORECASE, re.DOTALL, and re.VERBOSE

  Pillow, Computer Image Fundamentals, Coordinates and Box Tuples, Working with the Image Data Type, Working with the Image Data Type, Copying and Pasting Images onto Other Images, Copying and Pasting Images onto Other Images, Copying and Pasting Images onto Other Images, Rotating and Flipping Images, Rotating and Flipping Images, Changing Individual Pixels, Ideas for Similar Programs, Ideas for Similar Programs, Ideas for Similar Programs, Lines, Lines, Lines, Lines, Drawing Example

  copying and pasting in images, Copying and Pasting Images onto Other Images

  cropping images, Working with the Image Data Type

  drawing on images, Ideas for Similar Programs, Ideas for Similar Programs, Ideas for Similar Programs, Lines, Lines, Lines, Lines, Drawing Example

  ellipses, Lines

  example program, Lines

  ImageDraw module, Ideas for Similar Programs

  lines, Ideas for Similar Programs

  points, Ideas for Similar Programs

  polygons, Lines

  rectangles, Lines

  text, Drawing Example

  flipping images, Rotating and Flipping Images

  image attributes, Working with the Image Data Type

  module, Computer Image Fundamentals

  opening images, Coordinates and Box Tuples

  pixel manipulation, Changing Individual Pixels

  resizing images, Copying and Pasting Images onto Other Images

  rotating images, Rotating and Flipping Images

  transparent pixels, Copying and Pasting Images onto Other Images

  pipe character (|), Grouping with Parentheses, Managing Complex Regexes

  pip tool, Installing Third-Party Modules

  pixelMatchesColor() function, Analyzing the Screenshot, Step 3: Start Typing Data

  pixels, Computer Image Fundamentals, Changing Individual Pixels

  plaintext files, Finding File Sizes and Folder Contents

  plus sign (+), Optional Matching with the Question Mark, Matching Newlines with the Dot Character

  PNG format, Working with the Image Data Type

  point() method, Ideas for Similar Programs

  poll() method, Launching Other Programs from Python

  polygon() method, Lines

  Popen() function, Step 2: Create and Start Threads, Launching Other Programs from Python, Task Scheduler, launchd, and cron

  opening files with default applications, Task Scheduler, launchd, and cron

  passing command line arguments to, Launching Other Programs from Python

  position() function, Moving the Mouse, Step 3: Get and Print the Mouse Coordinates

  pprint() function, The setdefault() Method

  precedence of math operators, Entering Expressions into the Interactive Shell

  press() function, Pressing and Releasing the Keyboard, Review of the PyAutoGUI Functions, Step 4: Handle Select Lists and Radio Buttons

  print() function, Comments, The input() Function, Keyword Arguments and print(), Using the logging Module, Step 3: Start Typing Data

  logging and, Using the logging Module

  overview, Comments

  passing multiple arguments to, Keyword Arguments and print()

  using variables with, The input() Function

  processes, Step 2: Create and Start Threads, Step 2: Create and Start Threads, Launching Other Programs from Python, Launching Other Programs from Python, Launching Other Programs from Python, Task Scheduler, launchd, and cron, Task Scheduler, launchd, and cron, Project: Simple Countdown Program

  and countdown project, Project: Simple Countdown Program

  defined, Step 2: Create and Start Threads

  opening files with default applications, Task Scheduler, launchd, and cron

  opening websites, Task Scheduler, launchd, and cron

  passing command line arguments to, Launching Other Programs from Python

  poll() method, Launching Other Programs from Python

  Popen() function, Step 2: Create and Start Threads

  wait() method, Launching Other Programs from Python

  profiling code, The time Module

  programming, Conventions, What Is Python?, What Is Python?, Programming Is a Creative Activity, Comments, Mixing Boolean and Comparison Operators, Blocks of Code, Importing Modules, Functions, Local and Global Scope, Local and Global Variables with the Same Name, The global Statement, The global Statement, Example Program: Magic 8 Ball with a List

  blocks of code, Mixing Boolean and Comparison Operators

  comments, Comments

  creativity needed for, Programming Is a Creative Activity

  deduplicating code, Functions

  defined, Conventions

  exception handling, The global Statement

  execution, program, Blocks of Code

  functions as “black boxes”, The global Statement

  global scope, Local and Global Variables with the Same Name

  indentation, Example Program: Magic 8 Ball with a List

  local scope, Local and Global Scope

  math and, What Is Python?

  Python, What Is Python?

  terminating program with sy
s.exit(), Importing Modules

  projects, Copying and Pasting Strings with the pyperclip Module, Project: Adding Bullets to Wiki Markup, Combining re.IGNORECASE, re.DOTALL, and re.VERBOSE, Saving Variables with the pprint.pformat() Function, Step 4: Write Content to the Quiz and Answer Key Files, Creating and Adding to ZIP Files, Step 3: Form the New Filename and Rename the Files, Web Scraping, Getting Data from an Element’s Attributes, Step 3: Open Web Browsers for Each Result, Getting Rows and Columns from the Sheets, Writing Values to Cells, Encrypting PDFs, The delimiter and lineterminator Keyword Arguments, Reading JSON with the loads() Function, The time.sleep() Function, Project: Multithreaded XKCD Downloader, Project: Simple Countdown Program, Disconnecting from the IMAP Server, Project: “Just Text Me” Module, Project: Adding a Logo, Moving the Mouse, Analyzing the Screenshot, Review of the PyAutoGUI Functions

  Adding Bullets to Wiki Markup, Project: Adding Bullets to Wiki Markup

  Adding a Logo, Project: Adding a Logo

  Automatic Form Filler, Review of the PyAutoGUI Functions

  Backing Up a Folder into a ZIP File, Step 3: Form the New Filename and Rename the Files

  Combining Select Pages from Many PDFs, Encrypting PDFs

  Downloading All XKCD Comics, Step 3: Open Web Browsers for Each Result

  Extending the mouseNow Program, Analyzing the Screenshot

  Fetching Current Weather Data, Reading JSON with the loads() Function

  Generating Random Quiz Files, Saving Variables with the pprint.pformat() Function

  “I’m Feeling Lucky” Google Search, Getting Data from an Element’s Attributes

  “Just Text Me” Module, Project: “Just Text Me” Module

  mapIt.py with the webbrowser Module, Web Scraping

  Multiclipboard, Step 4: Write Content to the Quiz and Answer Key Files

  Multithreaded XKCD Downloader, Project: Multithreaded XKCD Downloader

  Password Locker, Copying and Pasting Strings with the pyperclip Module

  Phone Number and Email Address Extractor, Combining re.IGNORECASE, re.DOTALL, and re.VERBOSE

  Reading Data from a Spreadsheet, Getting Rows and Columns from the Sheets

  Removing the Header from CSV Files, The delimiter and lineterminator Keyword Arguments

  Renaming Files with American-Style Dates to European-Style Dates, Creating and Adding to ZIP Files

  Sending Member Dues Reminder Emails, Disconnecting from the IMAP Server

  Simple Countdown Program, Project: Simple Countdown Program

  Super Stopwatch, The time.sleep() Function

  Updating a Spreadsheet, Writing Values to Cells

  “Where Is the Mouse Right Now?”, Moving the Mouse

  putpixel() method, Changing Individual Pixels

  pyautogui.click() function, Project: Automatic Form Filler

  pyautogui.click() method, Clicking the Mouse

  pyautogui.doubleClick() function, Clicking the Mouse

  pyautogui.dragTo() function, Clicking the Mouse

  pyautogui.FailSafeException exception, Pauses and Fail-Safes

  pyautogui.hotkey() function, Pressing and Releasing the Keyboard

  pyautogui.keyDown() function, Key Names

  pyautogui.keyUp() function, Key Names

  pyautogui.middleClick() function, Clicking the Mouse

  pyautogui module, Controlling the Keyboard and Mouse with GUI Automation, Controlling the Keyboard and Mouse with GUI Automation, Pauses and Fail-Safes, Pauses and Fail-Safes, Pauses and Fail-Safes, Moving the Mouse, Step 3: Get and Print the Mouse Coordinates, Clicking the Mouse, Clicking the Mouse, Dragging the Mouse, Scrolling the Mouse, Project: Extending the mouseNow Program, Image Recognition, Image Recognition, Sending a String from the Keyboard, Key Names, Pressing and Releasing the Keyboard, Review of the PyAutoGUI Functions, Review of the PyAutoGUI Functions

  form filler project, Review of the PyAutoGUI Functions

  controlling keyboard, Image Recognition, Image Recognition, Sending a String from the Keyboard, Key Names, Pressing and Releasing the Keyboard

  hotkey combinations, Pressing and Releasing the Keyboard

  key names, Sending a String from the Keyboard

  pressing and releasing keys, Key Names

  sending string from keyboard, Image Recognition

  controlling mouse, Pauses and Fail-Safes, Step 3: Get and Print the Mouse Coordinates, Clicking the Mouse, Clicking the Mouse, Dragging the Mouse

  clicking mouse, Clicking the Mouse

  dragging mouse, Clicking the Mouse

  scrolling mouse, Dragging the Mouse

  documentation for, Controlling the Keyboard and Mouse with GUI Automation

  fail-safe feature, Pauses and Fail-Safes

  functions, Review of the PyAutoGUI Functions

  image recognition, Project: Extending the mouseNow Program

  importing, Moving the Mouse

  installing, Controlling the Keyboard and Mouse with GUI Automation

  pausing function calls, Pauses and Fail-Safes

  screenshots, Scrolling the Mouse

  pyautogui.mouseDown() function, Clicking the Mouse

  pyautogui.moveRel() function, Controlling Mouse Movement, Moving the Mouse

  pyautogui.moveTo() function, Controlling Mouse Movement

  pyautogui.PAUSE variable, Pauses and Fail-Safes

  pyautogui.position() function, Step 3: Get and Print the Mouse Coordinates

  pyautogui.press() function, Step 4: Handle Select Lists and Radio Buttons

  pyautogui.rightClick() function, Clicking the Mouse

  pyautogui.screenshot() function, Scrolling the Mouse

  pyautogui.size() function, Controlling Mouse Movement

  pyautogui.typewrite() function, Image Recognition, Sending a String from the Keyboard, Project: Automatic Form Filler

  py.exe program, Shebang Line

  pyobjc module, The pip Tool

  PyPDF2 module, Working with PDF and word Documents, PDF Documents, Extracting Text from PDFs, Decrypting PDFs, Creating PDFs, Copying Pages, Overlaying Pages, Overlaying Pages, Encrypting PDFs

  combining pages from multiple PDFs, Encrypting PDFs

  creating PDFs, Decrypting PDFs

  decrypting PDFs, Extracting Text from PDFs

  encrypting PDFs, Overlaying Pages

  extracting text from PDFs, PDF Documents

  format overview, Working with PDF and word Documents

  pages in PDFs, Creating PDFs, Copying Pages, Overlaying Pages

  copying, Creating PDFs

  overlaying, Overlaying Pages

  rotating, Copying Pages

  pyperclip module, Removing Whitespace with strip(), rstrip(), and lstrip()

  Python, Conventions, What Is Python?, What Is Python?, About This Book, About This Book, Downloading and Installing Python, Downloading and Installing Python, Starting IDLE, Starting IDLE, Entering Expressions into the Interactive Shell, Variable Names

  data types, Entering Expressions into the Interactive Shell

  downloading, About This Book

  example program, Variable Names

  help, Starting IDLE

  installing, About This Book

  interactive shell, Starting IDLE

  interpreter, defined, Downloading and Installing Python

  math and, What Is Python?

  overview, What Is Python?

  programming overview, Conventions

  starting IDLE, Downloading and Installing Python

  python-docx module, Step 4: Save the Results

  pyzmail module, Disconnecting from the SMTP Server, Fetching an Email and Marking It As Read

  PyzMessage objects, Fetching an Email and Marking It As Read

  Q

  question mark (?), Matching Multiple Groups with the Pipe, Matching Newlines with the Dot Character

  quit() method, Sending Special Keys, Disconnecting from the SMTP Server, Step 3: Send Customized Email Reminders

  quiz generator, Saving Variables with the pprin
t.pformat() Function, Saving Variables with the pprint.pformat() Function, Step 1: Store the Quiz Data in a Dictionary, Step 2: Create the Quiz File and Shuffle the Question Order, Step 2: Create the Quiz File and Shuffle the Question Order, Step 3: Create the Answer Options, Step 3: Create the Answer Options

  creating quiz file, Step 2: Create the Quiz File and Shuffle the Question Order

  creating answer options, Step 3: Create the Answer Options

  overview, Saving Variables with the pprint.pformat() Function

  shuffling question order, Step 2: Create the Quiz File and Shuffle the Question Order

  storing quiz data in dictionary, Step 1: Store the Quiz Data in a Dictionary

  writing content to files, Step 3: Create the Answer Options

  R

  radio buttons, Step 3: Start Typing Data

  raise_for_status() method, Downloading a Web Page with the requests.get() Function

  raise keyword, Debugging

  range() function, An Equivalent while Loop

  raw strings, Escape Characters, Creating Regex Objects

  Reader objects, Reader Objects

  reading files, Opening Files with the open() Function, Compressing Files with the zipfile Module

  readlines() method, Opening Files with the open() Function

  read() method, Opening Files with the open() Function

  rectangle() method, Lines

  Reddit, How to Find Help

  Reference objects, Charts

  references, The Tuple Data Type, Passing References

  overview, The Tuple Data Type

  passing, Passing References

  refresh() method, Sending Special Keys

  Regex objects, Finding Patterns of Text Without Regular Expressions, Creating Regex Objects

  creating, Finding Patterns of Text Without Regular Expressions

  matching, Creating Regex Objects

  regular expressions, Pattern Matching with Regular Expressions, Pattern Matching with Regular Expressions, Finding Patterns of Text Without Regular Expressions, Finding Patterns of Text Without Regular Expressions, Creating Regex Objects, Review of Regular Expression Matching, Grouping with Parentheses, Matching Multiple Groups with the Pipe, Optional Matching with the Question Mark, Optional Matching with the Question Mark, Matching One or More with the Plus, Matching One or More with the Plus, Greedy and Nongreedy Matching, Greedy and Nongreedy Matching, The findall() Method, Character Classes, Character Classes, The Caret and Dollar Sign Characters, Matching Newlines with the Dot Character, Case-Insensitive Matching, Case-Insensitive Matching, Managing Complex Regexes, Managing Complex Regexes, Combining re.IGNORECASE, re.DOTALL, and re.VERBOSE, Opening Your Browser’s Developer Tools

 

‹ Prev