Python 101

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Learn how to program with Python 3 from beginning to end. My book is made primarily for beginners. However, at least two-thirds of it is aimed at intermediate programmers. You may be wondering how that works. The book will be split into five parts: beginner material, the Python standard library, intermediate topics, 3rd party modules, and distribution.

Author(s): Michael Driscoll
Publisher: Michael Driscoll
Year: 2016

Language: English
Pages: 296

Table of Contents
Introduction
A Brief History of Python
About the Author
Conventions
Requirements
Reader Feedback
Errata
Part I - Learning the Basics
Chapter 1 - IDLE Programming
Using IDLE
Other Tips
Wrapping Up
Chapter 2 - All About Strings
How to Create a String
String Concatenation
String Methods
String Slicing
String Formatting
Wrapping Up
Chapter 3 - Lists, Tuples and Dictionaries
Lists
Tuples
Dictionaries
Wrapping Up
Chapter 4 - Conditional Statements
The if statement
Boolean Operations
Checking for Nothing
Special Characters
if __name__ == ``__main__''
Wrapping Up
Chapter 5 - Loops
The for Loop
The while Loop
What else is for in loops
Wrapping Up
Chapter 6 - Python Comprehensions
List Comprehensions
Dictionary Comprehensions
Set Comprehensions
Wrapping Up
Chapter 7 - Exception Handling
Common Exceptions
How to Handle Exceptions
The finally Statement
try, except, or else!
Wrapping Up
Chapter 8 - Working with Files
How to Read a File
How To Read Files Piece by Piece
How to Read a Binary File
Writing Files in Python
Using the with Operator
Catching Errors
Wrapping Up
Chapter 9 - Importing
import this
Using from to import
Importing Everything!
Wrapping Up
Chapter 10 - Functions
An Empty Function (the stub)
Passing Arguments to a Function
Keyword Arguments
*args and **kwargs
A Note on Scope and Globals
Coding Tips
Wrapping Up
Chapter 11 - Classes
Creating a Class
What is self?
Subclasses
Wrapping Up
Part II - Learning from the Library
Chapter 12 - Introspection
The Python Type
The Python Dir
Python Help!
Wrapping Up
Chapter 13 - The csv Module
Reading a CSV File
Writing a CSV File
Wrapping Up
Chapter 14 - configparser
Creating a Config File
How to Read, Update and Delete Options
How to Use Interpolation
Wrapping Up
Chapter 15 - Logging
Creating a Simple Logger
How to log From Multiple Modules (and Formatting too!)
Configuring Logs for Work and Pleasure
Wrapping Up
Chapter 16 - The os Module
os.name
os.environ, os.getenv() and os.putenv()
os.chdir() and os.getcwd()
os.mkdir() and os.makedirs()
os.remove() and os.rmdir()
os.rename(src, dst)
os.startfile()
os.walk()
os.path
os.path.basename
os.path.dirname
os.path.exists
os.path.isdir / os.path.isfile
os.path.join
os.path.split
Wrapping Up
Chapter 17 - The email / smtplib Module
Email Basics - How to Send an Email with smtplib
Sending Multiple Emails at Once
Send email using the TO, CC and BCC lines
Add an attachment / body using the email module
Wrapping Up
Chapter 18 - The sqlite Module
How to Create a Database and INSERT Some Data
Updating and Deleting Records
Basic SQLite Queries
Wrapping Up
Chapter 19 - The subprocess Module
The call function
The Popen Class
Learning to Communicate
Wrapping Up
Chapter 20 - The sys Module
sys.argv
sys.executable
sys.exit
sys.path
sys.platform
sys.stdin / stdout / stderr
Wrapping Up
Chapter 21 - The threading module
Using Threads
Writing a Threaded Downloader
Using Queues
Wrapping Up
Chapter 22 - Working with Dates and Time
The datetime Module
datetime.date
datetime.datetime
datetime.timedelta
The time Module
time.ctime
time.sleep
time.strftime
time.time
Wrapping Up
Chapter 23 - The xml module
Working with minidom
Parsing with ElementTree
How to Create XML with ElementTree
How to Edit XML with ElementTree
How to Parse XML with ElementTree
Wrapping Up
Part III - Intermediate Odds and Ends
Chapter 24 - The Python Debugger
How to Start the Debugger
Stepping Through the Code
Setting breakpoints
Wrapping Up
Chapter 25 - Decorators
A Simple Function
Creating a Logging Decorator
Built-in Decorators
@classmethod and @staticmethod
Python Properties
Replacing Setters and Getters with a Python property
Wrapping Up
Chapter 26 - The lambda
Tkinter + lambda
Wrapping Up
Chapter 27 - Code Profiling
Profiling Your Code with cProfile
Wrapping Up
Chapter 28 - An Intro to Testing
Testing with doctest
Running doctest via the Terminal
Running doctest Inside a Module
Running doctest From a Separate File
Test Driven Development with unittest
The First Test
The Second Test
The Third (and Final) Test
Other Notes
Wrapping Up
Part IV - Tips, Tricks and Tutorials
Chapter 29 - Installing Modules
Installing from Source
Using easy_install
Using pip
A Note on Dependencies
Wrapping Up
Chapter 30 - ConfigObj
Getting Started
Using a configspec
Wrapping Up
Chapter 31 - Parsing XML with lxml
Parsing XML with lxml
Parsing the Book Example
Parsing XML with lxml.objectify
Creating XML with lxml.objectify
Wrapping Up
Chapter 32 - Python Code Analysis
Getting Started with pylint
Analyzing Your Code
Getting Started with pyflakes
Wrapping Up
Chapter 33 - The requests package
Using requests
How to Submit a Web Form
Wrapping Up
Chapter 34 - SQLAlchemy
How to Create a Database
How to Insert / Add Data to Your Tables
How to Modify Records with SQLAlchemy
How to Delete Records in SQLAlchemy
The Basic SQL Queries of SQLAlchemy
Wrapping Up
Chapter 35 - virtualenv
Installation
Creating a Virtual Environment
Wrapping Up
Part V - Packaging and Distribution
Chapter 36 - Creating Modules and Packages
How to Create a Python Module
How to Create a Python Package
Wrapping Up
Chapter 37 - How to Add Your Code to PyPI
Creating a setup.py File
Registering Packages
Uploading Packages to PyPI
Wrapping Up
Chapter 38 - The Python egg
Creating an egg
Wrapping Up
Chapter 39 - Python wheels
Getting Started
Creating a wheel
Installing a Python wheel
Wrapping Up
Chapter 40 - py2exe
Creating a Simple GUI
The py2exe setup.py file
Creating an Advanced setup.py File
Wrapping Up
Chapter 41 - bbfreeze
Getting Started with bbfreeze
Using bbfreeze's Advanced Configuration
Wrapping Up
Chapter 42 - cx_Freeze
Getting Started with cx_Freeze
Advanced cx_Freeze - Using a setup.py File
Wrapping Up
Chapter 43 - PyInstaller
Getting Started with PyInstaller
PyInstaller and wxPython
Wrapping Up
Chapter 44 - Creating an Installer
Getting Started with GUI2Exe
Let's Make an Installer!
Wrapping Up
Appendix A: Putting It All Together
The Background
The Specification
Breaking the Specification Down
Turning Chapters Into a Book
Reading the Customer CSV File
Emailing the PDF
Putting it all Together
Wrapping Up