Introducing Python: Modern Computing in Simple Packages

$5.00

Categories: , Tag: GTIN: 9781492051367
Introducing Python: Modern Computing in Simple Packages
Size: 12 MB (13105027 bytes) Extension: pdf
Author(s): Bill Lubanovic

Publisher: O’Reilly Media, Year: 2019

ISBN: 1492051365,9781492051367

Description:
Easy to understand and fun to read, this updated edition of Introducing Python is ideal for beginning programmers as well as those new to the language. Author Bill Lubanovic takes you from the basics to more involved and varied topics, mixing tutorials with cookbook-style code recipes to explain concepts in Python 3. End-of-chapter exercises help you practice what you’ve learned.

You’ll gain a strong foundation in the language, including best practices for testing, debugging, code reuse, and other development tips. This book also shows you how to use Python for applications in business, science, and the arts, using various Python tools and open source packages.

Table of contents :
Cover
Copyright
Table of Contents
Preface
Audience
Changes in the Second Edition
Outline
Python Versions
Conventions Used in This Book
Using Code Examples
O’Reilly Online Learning
How to Contact Us
Acknowledgments
Part I. Python Basics
Chapter 1. A Taste of Py
Mysteries
Little Programs
A Bigger Program
Python in the Real World
Python Versus the Language from Planet X
Why Python?
Why Not Python?
Python 2 Versus Python 3
Installing Python
Running Python
Using the Interactive Interpreter
Using Python Files
What’s Next?
Your Moment of Zen
Coming Up
Things to Do
Chapter 2. Data: Types, Values, Variables, and Names
Python Data Are Objects
Types
Mutability
Literal Values
Variables
Assignment
Variables Are Names, Not Places
Assigning to Multiple Names
Reassigning a Name
Copying
Choose Good Variable Names
Coming Up
Things to Do
Chapter 3. Numbers
Booleans
Integers
Literal Integers
Integer Operations
Integers and Variables
Precedence
Bases
Type Conversions
How Big Is an int?
Floats
Math Functions
Coming Up
Things to Do
Chapter 4. Choose with if
Comment with #
Continue Lines with \
Compare with if, elif, and else
What Is True?
Do Multiple Comparisons with in
New: I Am the Walrus
Coming Up
Things to Do
Chapter 5. Text Strings
Create with Quotes
Create with str()
Escape with \
Combine by Using +
Duplicate with *
Get a Character with []
Get a Substring with a Slice
Get Length with len()
Split with split()
Combine by Using join()
Substitute by Using replace()
Strip with strip()
Search and Select
Case
Alignment
Formatting
Old style: %
New style: {} and format()
Newest Style: f-strings
More String Things
Coming Up
Things to Do
Chapter 6. Loop with while and for
Repeat with while
Cancel with break
Skip Ahead with continue
Check break Use with else
Iterate with for and in
Cancel with break
Skip with continue
Check break Use with else
Generate Number Sequences with range()
Other Iterators
Coming Up
Things to Do
Chapter 7. Tuples and Lists
Tuples
Create with Commas and ()
Create with tuple()
Combine Tuples by Using +
Duplicate Items with *
Compare Tuples
Iterate with for and in
Modify a Tuple
Lists
Create with []
Create or Convert with list()
Create from a String with split()
Get an Item by [ offset ]
Get Items with a Slice
Add an Item to the End with append()
Add an Item by Offset with insert()
Duplicate All Items with *
Combine Lists by Using extend() or +
Change an Item by [ offset ]
Change Items with a Slice
Delete an Item by Offset with del
Delete an Item by Value with remove()
Get an Item by Offset and Delete It with pop()
Delete All Items with clear()
Find an Item’s Offset by Value with index()
Test for a Value with in
Count Occurrences of a Value with count()
Convert a List to a String with join()
Reorder Items with sort() or sorted()
Get Length with len()
Assign with =
Copy with copy(), list(), or a Slice
Copy Everything with deepcopy()
Compare Lists
Iterate with for and in
Iterate Multiple Sequences with zip()
Create a List with a Comprehension
Lists of Lists
Tuples Versus Lists
There Are No Tuple Comprehensions
Coming Up
Things to Do
Chapter 8. Dictionaries and Sets
Dictionaries
Create with {}
Create with dict()
Convert with dict()
Add or Change an Item by [ key ]
Get an Item by [key] or with get()
Get All Keys with keys()
Get All Values with values()
Get All Key-Value Pairs with items()
Get Length with len()
Combine Dictionaries with {**a, **b}
Combine Dictionaries with update()
Delete an Item by Key with del
Get an Item by Key and Delete It with pop()
Delete All Items with clear()
Test for a Key with in
Assign with =
Copy with copy()
Copy Everything with deepcopy()
Compare Dictionaries
Iterate with for and in
Dictionary Comprehensions
Sets
Create with set()
Convert with set()
Get Length with len()
Add an Item with add()
Delete an Item with remove()
Iterate with for and in
Test for a Value with in
Combinations and Operators
Set Comprehensions
Create an Immutable Set with frozenset()
Data Structures So Far
Make Bigger Data Structures
Coming Up
Things to Do
Chapter 9. Functions
Define a Function with def
Call a Function with Parentheses
Arguments and Parameters
None Is Useful
Positional Arguments
Keyword Arguments
Specify Default Parameter Values
Explode/Gather Positional Arguments with *
Explode/Gather Keyword Arguments with **
Keyword-Only Arguments
Mutable and Immutable Arguments
Docstrings
Functions Are First-Class Citizens
Inner Functions
Closures
Anonymous Functions: lambda
Generators
Generator Functions
Generator Comprehensions
Decorators
Namespaces and Scope
Uses of _ and __ in Names
Recursion
Async Functions
Exceptions
Handle Errors with try and except
Make Your Own Exceptions
Coming Up
Things to Do
Chapter 10. Oh Oh: Objects and Classes
What Are Objects?
Simple Objects
Define a Class with class
Attributes
Methods
Initialization
Inheritance
Inherit from a Parent Class
Override a Method
Add a Method
Get Help from Your Parent with super()
Multiple Inheritance
Mixins
In self Defense
Attribute Access
Direct Access
Getters and Setters
Properties for Attribute Access
Properties for Computed Values
Name Mangling for Privacy
Class and Object Attributes
Method Types
Instance Methods
Class Methods
Static Methods
Duck Typing
Magic Methods
Aggregation and Composition
When to Use Objects or Something Else
Named Tuples
Dataclasses
Attrs
Coming Up
Things to Do
Chapter 11. Modules, Packages, and Goodies
Modules and the import Statement
Import a Module
Import a Module with Another Name
Import Only What You Want from a Module
Packages
The Module Search Path
Relative and Absolute Imports
Namespace Packages
Modules Versus Objects
Goodies in the Python Standard Library
Handle Missing Keys with setdefault() and defaultdict()
Count Items with Counter()
Order by Key with OrderedDict()
Stack + Queue == deque
Iterate over Code Structures with itertools
Print Nicely with pprint()
Get Random
More Batteries: Get Other Python Code
Coming Up
Things to Do
Part II. Python in Practice
Chapter 12. Wrangle and Mangle Data
Text Strings: Unicode
Python 3 Unicode Strings
UTF-8
Encode
Decode
HTML Entities
Normalization
For More Information
Text Strings: Regular Expressions
Find Exact Beginning Match with match()
Find First Match with search()
Find All Matches with findall()
Split at Matches with split()
Replace at Matches with sub()
Patterns: Special Characters
Patterns: Using Specifiers
Patterns: Specifying match() Output
Binary Data
bytes and bytearray
Convert Binary Data with struct
Other Binary Data Tools
Convert Bytes/Strings with binascii()
Bit Operators
A Jewelry Analogy
Coming Up
Things to Do
Chapter 13. Calendars and Clocks
Leap Year
The datetime Module
Using the time Module
Read and Write Dates and Times
All the Conversions
Alternative Modules
Coming Up
Things to Do
Chapter 14. Files and Directories
File Input and Output
Create or Open with open()
Write a Text File with print()
Write a Text File with write()
Read a Text File with read(), readline(), or readlines()
Write a Binary File with write()
Read a Binary File with read()
Close Files Automatically by Using with
Change Position with seek()
Memory Mapping
File Operations
Check Existence with exists()
Check Type with isfile()
Copy with copy()
Change Name with rename()
Link with link() or symlink()
Change Permissions with chmod()
Change Ownership with chown()
Delete a File with remove()
Directory Operations
Create with mkdir()
Delete with rmdir()
List Contents with listdir()
Change Current Directory with chdir()
List Matching Files with glob()
Pathnames
Get a Pathname with abspath()
Get a symlink Pathname with realpath()
Build a Pathname with os.path.join()
Use pathlib
BytesIO and StringIO
Coming Up
Things to Do
Chapter 15. Data in Time: Processes and Concurrency
Programs and Processes
Create a Process with subprocess
Create a Process with multiprocessing
Kill a Process with terminate()
Get System Info with os
Get Process Info with psutil
Command Automation
Invoke
Other Command Helpers
Concurrency
Queues
Processes
Threads
concurrent.futures
Green Threads and gevent
twisted
asyncio
Redis
Beyond Queues
Coming Up
Things to Do
Chapter 16. Data in a Box: Persistent Storage
Flat Text Files
Padded Text Files
Tabular Text Files
CSV
XML
An XML Security Note
HTML
JSON
YAML
Tablib
Pandas
Configuration Files
Binary Files
Padded Binary Files and Memory Mapping
Spreadsheets
HDF5
TileDB
Relational Databases
SQL
DB-API
SQLite
MySQL
PostgreSQL
SQLAlchemy
Other Database Access Packages
NoSQL Data Stores
The dbm Family
Memcached
Redis
Document Databases
Time Series Databases
Graph Databases
Other NoSQL
Full-Text Databases
Coming Up
Things to Do
Chapter 17. Data in Space: Networks
TCP/IP
Sockets
Scapy
Netcat
Networking Patterns
The Request-Reply Pattern
ZeroMQ
Other Messaging Tools
The Publish-Subscribe Pattern
Redis
ZeroMQ
Other Pub-Sub Tools
Internet Services
Domain Name System
Python Email Modules
Other Protocols
Web Services and APIs
Data Serialization
Serialize with pickle
Other Serialization Formats
Remote Procedure Calls
XML RPC
JSON RPC
MessagePack RPC
Zerorpc
gRPC
Twirp
Remote Management Tools
Big Fat Data
Hadoop
Spark
Disco
Dask
Clouds
Amazon Web Services
Google Cloud
Microsoft Azure
OpenStack
Docker
Kubernetes
Coming Up
Things to Do
Chapter 18. The Web, Untangled
Web Clients
Test with telnet
Test with curl
Test with httpie
Test with httpbin
Python’s Standard Web Libraries
Beyond the Standard Library: requests
Web Servers
The Simplest Python Web Server
Web Server Gateway Interface (WSGI)
ASGI
Apache
NGINX
Other Python Web Servers
Web Server Frameworks
Bottle
Flask
Django
Other Frameworks
Database Frameworks
Web Services and Automation
webbrowser
webview
Web APIs and REST
Crawl and Scrape
Scrapy
BeautifulSoup
Requests-HTML
Let’s Watch a Movie
Coming Up
Things to Do
Chapter 19. Be a Pythonista
About Programming
Find Python Code
Install Packages
Use pip
Use virtualenv
Use pipenv
Use a Package Manager
Install from Source
Integrated Development Environments
IDLE
PyCharm
IPython
Jupyter Notebook
JupyterLab
Name and Document
Add Type Hints
Test
Check with pylint, pyflakes, flake8, or pep8
Test with unittest
Test with doctest
Test with nose
Other Test Frameworks
Continuous Integration
Debug Python Code
Use print()
Use Decorators
Use pdb
Use breakpoint()
Log Error Messages
Optimize
Measure Timing
Algorithms and Data Structures
Cython, NumPy, and C Extensions
PyPy
Numba
Source Control
Mercurial
Git
Distribute Your Programs
Clone This Book
How You Can Learn More
Books
Websites
Groups
Conferences
Getting a Python Job
Coming Up
Things to Do
Chapter 20. Py Art
2-D Graphics
Standard Library
PIL and Pillow
ImageMagick
3-D Graphics
3-D Animation
Graphical User Interfaces
Plots, Graphs, and Visualization
Matplotlib
Seaborn
Bokeh
Games
Audio and Music
Coming Up
Things to Do
Chapter 21. Py at Work
The Microsoft Office Suite
Carrying Out Business Tasks
Processing Business Data
Extracting, Transforming, and Loading
Data Validation
Additional Sources of Information
Open Source Python Business Packages
Python in Finance
Business Data Security
Maps
Formats
Draw a Map from a Shapefile
Geopandas
Other Mapping Packages
Applications and Data
Coming Up
Things to Do
Chapter 22. Py Sci
Math and Statistics in the Standard Library
Math Functions
Working with Complex Numbers
Calculate Accurate Floating Point with decimal
Perform Rational Arithmetic with fractions
Use Packed Sequences with array
Handling Simple Stats with statistics
Matrix Multiplication
Scientific Python
NumPy
Make an Array with array()
Make an Array with arange()
Make an Array with zeros(), ones(), or random()
Change an Array’s Shape with reshape()
Get an Element with []
Array Math
Linear Algebra
SciPy
SciKit
Pandas
Python and Scientific Areas
Coming Up
Things to Do
Appendix A. Hardware and Software for Beginning Programmers
Hardware
Caveman Computers
Electricity
Inventions
An Idealized Computer
The CPU
Memory and Caches
Storage
Inputs
Outputs
Relative Access Times
Software
In the Beginning Was the Bit
Machine Language
Assembler
Higher-Level Languages
Operating Systems
Virtual Machines
Containers
Distributed Computing and Networks
The Cloud
Kubernetes
Appendix B. Install Python 3
Check Your Python Version
Install Standard Python
macOS
Windows
Linux or Unix
Install the pip Package Manager
Install virtualenv
Other Packaging Solutions
Install Anaconda
Install Anaconda’s Package Manager conda
Appendix C. Something Completely Different: Async
Coroutines and Event Loops
Asyncio Alternatives
Async Versus…
Async Frameworks and Servers
Appendix D. Answers to Exercises
1. A Taste of Py
2. Data: Types, Values, Variables, and Names
3. Numbers
4. Choose with if
5. Text Strings
6. Loop with while and for
7. Tuples and Lists
8. Dictionaries
9. Functions
10. Oh Oh: Objects and Classes
11. Modules, Packages, and Goodies
12. Wrangle and Mangle Data
13. Calendars and Clocks
14. Files and Directories
15. Data in Time: Processes and Concurrency
16. Data in a Box: Persistent Storage
17. Data in Space: Networks
18. The Web, Untangled
19. Be a Pythonista
20. Py Art
21. Py at Work
22. PySci
Appendix E. Cheat Sheets
Operator Precedence
String Methods
Change Case
Search
Modify
Format
String Type
String Module Attributes
Coda
Index
About the Author
Colophon

Stay Connected

We don’t spam! Read our privacy policy for more info.

Shopping Cart