Automate the boring stuff with Python practical programming for total beginners
Automate the Boring Stuff with Python teaches simple programming skills to automate everyday computer tasks.
Otros Autores: | |
---|---|
Formato: | Libro electrónico |
Idioma: | Inglés |
Publicado: |
San Francisco, California :
No Starch Press
©2015
|
Materias: | |
Ver en Biblioteca Universitat Ramon Llull: | https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009630034506719 |
Tabla de Contenidos:
- Intro
- Automate the Boring Stuff with Python: Practical Programming for Total Beginners
- Dedication
- About the Author
- About the Tech Reviewer
- Acknowledgments
- Introduction
- Whom Is This Book For?
- Conventions
- What Is Programming?
- What Is Python?
- Programmers Don't Need to Know Much Math
- Programming Is a Creative Activity
- About This Book
- Downloading and Installing Python
- Starting IDLE
- The Interactive Shell
- How to Find Help
- Asking Smart Programming Questions
- Summary
- I. Python Programming Basics
- 1. Python Basics
- Entering Expressions into the Interactive Shell
- The Integer, Floating-Point, and String Data Types
- String Concatenation and Replication
- Storing Values in Variables
- Assignment Statements
- Variable Names
- Your First Program
- Dissecting Your Program
- Comments
- The print() Function
- The input() Function
- Printing the User's Name
- The len() Function
- The str(), int(), and float() Functions
- Summary
- Practice Questions
- 2. Flow Control
- Boolean Values
- Comparison Operators
- Boolean Operators
- Binary Boolean Operators
- The not Operator
- Mixing Boolean and Comparison Operators
- Elements of Flow Control
- Conditions
- Blocks of Code
- Program Execution
- Flow Control Statements
- if Statements
- else Statements
- elif Statements
- while Loop Statements
- An Annoying while Loop
- break Statements
- continue Statements
- for Loops and the range() Function
- An Equivalent while Loop
- The Starting, Stopping, and Stepping Arguments to range()
- Importing Modules
- from import Statements
- Ending a Program Early with sys.exit()
- Summary
- Practice Questions
- 3. Functions
- def Statements with Parameters
- Return Values and return Statements
- The None Value
- Keyword Arguments and print()
- Local and Global Scope.
- Local Variables Cannot Be Used in the Global Scope
- Local Scopes Cannot Use Variables in Other Local Scopes
- Global Variables Can Be Read from a Local Scope
- Local and Global Variables with the Same Name
- The global Statement
- Exception Handling
- A Short Program: Guess the Number
- Summary
- Practice Questions
- Practice Projects
- The Collatz Sequence
- Input Validation
- 4. Lists
- The List Data Type
- Getting Individual Values in a List with Indexes
- Negative Indexes
- Getting Sublists with Slices
- Getting a List's Length with len()
- Changing Values in a List with Indexes
- List Concatenation and List Replication
- Removing Values from Lists with del Statements
- Working with Lists
- Using for Loops with Lists
- The in and not in Operators
- The Multiple Assignment Trick
- Augmented Assignment Operators
- Methods
- Finding a Value in a List with the index() Method
- Adding Values to Lists with the append() and insert() Methods
- Removing Values from Lists with remove()
- Sorting the Values in a List with the sort() Method
- Example Program: Magic 8 Ball with a List
- List-like Types: Strings and Tuples
- Mutable and Immutable Data Types
- The Tuple Data Type
- Converting Types with the list() and tuple() Functions
- References
- Passing References
- The copy Module's copy() and deepcopy() Functions
- Summary
- Practice Questions
- Practice Projects
- Comma Code
- Character Picture Grid
- 5. Dictionaries and Structuring Data
- The Dictionary Data Type
- Dictionaries vs. Lists
- The keys(), values(), and items() Methods
- Checking Whether a Key or Value Exists in a Dictionary
- The get() Method
- The setdefault() Method
- Pretty Printing
- Using Data Structures to Model Real-World Things
- A Tic-Tac-Toe Board
- Nested Dictionaries and Lists
- Summary
- Practice Questions.
- Practice Projects
- Fantasy Game Inventory
- List to Dictionary Function for Fantasy Game Inventory
- 6. Manipulating Strings
- Working with Strings
- String Literals
- Double Quotes
- Escape Characters
- Raw Strings
- Multiline Strings with Triple Quotes
- Multiline Comments
- Indexing and Slicing Strings
- The in and not in Operators with Strings
- Useful String Methods
- The upper(), lower(), isupper(), and islower() String Methods
- The isX String Methods
- The startswith() and endswith() String Methods
- The join() and split() String Methods
- Justifying Text with rjust(), ljust(), and center()
- Removing Whitespace with strip(), rstrip(), and lstrip()
- Copying and Pasting Strings with the pyperclip Module
- Project: Password Locker
- Step 1: Program Design and Data Structures
- Step 2: Handle Command Line Arguments
- Step 3: Copy the Right Password
- Project: Adding Bullets to Wiki Markup
- Step 1: Copy and Paste from the Clipboard
- Step 2: Separate the Lines of Text and Add the Star
- Step 3: Join the Modified Lines
- Summary
- Practice Questions
- Practice Project
- Table Printer
- II. Automating Tasks
- 7. Pattern Matching with Regular Expressions
- Finding Patterns of Text Without Regular Expressions
- Finding Patterns of Text with Regular Expressions
- Creating Regex Objects
- Matching Regex Objects
- Review of Regular Expression Matching
- More Pattern Matching with Regular Expressions
- Grouping with Parentheses
- Matching Multiple Groups with the Pipe
- Optional Matching with the Question Mark
- Matching Zero or More with the Star
- Matching One or More with the Plus
- Matching Specific Repetitions with Curly Brackets
- Greedy and Nongreedy Matching
- The findall() Method
- Character Classes
- Making Your Own Character Classes
- The Caret and Dollar Sign Characters.
- The Wildcard Character
- Matching Everything with Dot-Star
- Matching Newlines with the Dot Character
- Review of Regex Symbols
- Case-Insensitive Matching
- Substituting Strings with the sub() Method
- Managing Complex Regexes
- Combining re.IGNORECASE, re.DOTALL, and re.VERBOSE
- Project: Phone Number and Email Address Extractor
- Step 1: Create a Regex for Phone Numbers
- Step 2: Create a Regex for Email Addresses
- Step 3: Find All Matches in the Clipboard Text
- Step 4: Join the Matches into a String for the Clipboard
- Running the Program
- Ideas for Similar Programs
- Summary
- Practice Questions
- Practice Projects
- Strong Password Detection
- Regex Version of strip()
- 8. Reading and Writing Files
- Files and File Paths
- Backslash on Windows and Forward Slash on OS X and Linux
- The Current Working Directory
- Absolute vs. Relative Paths
- Creating New Folders with os.makedirs()
- The os.path Module
- Handling Absolute and Relative Paths
- Finding File Sizes and Folder Contents
- Checking Path Validity
- The File Reading/Writing Process
- Opening Files with the open() Function
- Reading the Contents of Files
- Writing to Files
- Saving Variables with the shelve Module
- Saving Variables with the pprint.pformat() Function
- Project: Generating Random Quiz Files
- Step 1: Store the Quiz Data in a Dictionary
- Step 2: Create the Quiz File and Shuffle the Question Order
- Step 3: Create the Answer Options
- Step 4: Write Content to the Quiz and Answer Key Files
- Project: Multiclipboard
- Step 1: Comments and Shelf Setup
- Step 2: Save Clipboard Content with a Keyword
- Step 3: List Keywords and Load a Keyword's Content
- Summary
- Practice Questions
- Practice Projects
- Extending the Multiclipboard
- Mad Libs
- Regex Search
- 9. Organizing Files
- The shutil Module.
- Copying Files and Folders
- Moving and Renaming Files and Folders
- Permanently Deleting Files and Folders
- Safe Deletes with the send2trash Module
- Walking a Directory Tree
- Compressing Files with the zipfile Module
- Reading ZIP Files
- Extracting from ZIP Files
- Creating and Adding to ZIP Files
- Project: Renaming Files with American-Style Dates to European-Style Dates
- Step 1: Create a Regex for American-Style Dates
- Step 2: Identify the Date Parts from the Filenames
- Step 3: Form the New Filename and Rename the Files
- Ideas for Similar Programs
- Project: Backing Up a Folder into a ZIP File
- Step 1: Figure Out the ZIP File's Name
- Step 2: Create the New ZIP File
- Step 3: Walk the Directory Tree and Add to the ZIP File
- Ideas for Similar Programs
- Summary
- Practice Questions
- Practice Projects
- Selective Copy
- Deleting Unneeded Files
- Filling in the Gaps
- 10. Debugging
- Raising Exceptions
- Getting the Traceback as a String
- Assertions
- Using an Assertion in a Traffic Light Simulation
- Disabling Assertions
- Logging
- Using the logging Module
- Don't Debug with print()
- Logging Levels
- Disabling Logging
- Logging to a File
- IDLE's Debugger
- Go
- Step
- Over
- Out
- Quit
- Debugging a Number Adding Program
- Breakpoints
- Summary
- Practice Questions
- Practice Project
- Debugging Coin Toss
- 11. Web Scraping
- Project: mapit.py with the webbrowser Module
- Step 1: Figure Out the URL
- Step 2: Handle the Command Line Arguments
- Step 3: Handle the Clipboard Content and Launch the Browser
- Ideas for Similar Programs
- Downloading Files from the Web with the requests Module
- Downloading a Web Page with the requests.get() Function
- Checking for Errors
- Saving Downloaded Files to the Hard Drive
- HTML
- Resources for Learning HTML
- A Quick Refresher.
- Viewing the Source HTML of a Web Page.