Cover image for Introducing Python

Book description

With Introducing Python, Bill Lubanovic brings years of knowledge as a programmer, system administrator, and author to a book of impressive depth that remains fun to read and simple enough for non-programmers to learn from. In addition to giving a strong foundation in the language itself, Lubanovic shows how to use it for a range of applications in business, science, and the arts, drawing on the rich collection of open source packages developed by Python fans.

Table of Contents

  1. Preface
    1. Audience
    2. Outline
    3. Python versions
    4. Conventions Used in This Book
    5. How to Contact Us
    6. Acknowledgements
  2. 1. A taste of Py
    1. Python in the real world
    2. Python versus language X
    3. So, why Python?
    4. When not to use Python
    5. Python 2 versus Python 3
    6. Installing Python
    7. Running Python
      1. Use the interactive interpreter
      2. Use Python files
      3. What’s next?
    8. Your moment of zen
    9. Things to do
  3. 2. Py ingredients: numbers, strings, and variables
    1. Variables, names, and objects
    2. Numbers
      1. Integers
      2. Precedence
      3. Bases
      4. Type Conversions
      5. How big is an
      6. Floats
      7. Math functions
    3. Strings
      1. Create with quotes
      2. Convert with
      3. Escape with
      4. Combine with
      5. Duplicate with
      6. Get a character with
      7. Slice with
      8. Get length with
      9. Split with
      10. Combine with
      11. Play with strings
      12. Case and alignment
      13. Substitute with
      14. More string things
    4. Things to do
  4. 3. Py filling: lists, tuples, dictionaries, and sets
    1. Lists and tuples
    2. Lists
      1. Create with
      2. Convert with
      3. Get an item with
      4. Lists of lists
      5. Change an item by
      6. Get items by offset range with a slice
      7. Add an item to the end with
      8. Combine lists with
      9. Add an item by offset with
      10. Delete an item by offset with
      11. Delete an item by value with
      12. Get an item by offset and delete it with
      13. Find an item’s offset by value with
      14. Test for a value with
      15. Count occurrences of a value with
      16. Convert to a string with
      17. Reorder with
      18. Get length with
      19. Assign with
    3. Tuples
      1. Create a tuple with
      2. Tuple uses
    4. Dictionaries
      1. Create with
      2. Convert with
      3. Add or change an item by
      4. Combine dictionaries with
      5. Delete an item by key with
      6. Delete all items with
      7. Test for a key with
      8. Get an item by
      9. Get all keys with
      10. Get all values with
      11. Get all key-value pairs with
      12. Assign with
    5. Sets
      1. Create with
      2. Convert with
      3. Test for value with
      4. Combinations and operators
    6. Compare data structures
    7. Make bigger data structures
    8. Things to do
  5. 4. Py crust: code structures
    1. Comment with
    2. Continue lines with
    3. Compare with
      1. What is True?
    4. Repeat with
      1. Cancel with
      2. Skip ahead with
      3. Check
    5. Iterate with
      1. Cancel with
      2. Skip with
      3. Check
      4. Iterate multiple sequences with
      5. Generate number sequences with
      6. Other iterators
    6. Comprehensions
      1. List comprehensions
      2. Dictionary comprehensions
      3. Set comprehensions
      4. Generator comprehensions
    7. Functions
      1. Positional arguments
      2. Keyword arguments
      3. Default parameter values
      4. Gather positional arguments with
      5. Gather keyword arguments with
      6. Docstrings
      7. Functions are first-class citizens
      8. Inner functions
      9. Closures
      10. Anonymous functions:
    8. Generators
    9. Decorators
    10. Namespaces and scope
      1. Uses of
    11. Handle errors with
    12. Make your own exceptions
    13. Things to do
  6. 5. Py boxes: modules, packages, and programs
    1. Standalone programs
    2. Command line arguments
    3. Modules and
      1. Import a module
      2. Import a module with another name
      3. Import only what you want from a module
      4. Module search path
    4. Packages
    5. The Python standard library
      1. Handle missing keys with
      2. Count items with
      3. Order by key with
      4. Stack + queue ==
      5. Code structures with
      6. Nice printing with
    6. More batteries: get other Python code
    7. Things to do
  7. 6. Oh oh: objects and classes
    1. What are objects?
    2. Make a class with
    3. Inheritance
    4. Override a method
    5. Add a method
    6. Get help from your parent with
    7. defense
    8. Get and set attribute values with properties
    9. Name mangling for privacy
    10. Method types
    11. Duck typing
    12. Special methods
    13. Composition
    14. When to use classes and objects versus modules
      1. Named tuples
    15. Things to do
  8. 7. Mangle data like a pro
    1. Text strings
      1. Unicode
        1. Python 3 Unicode strings
        2. Encode and decode with UTF-8
        3. Encoding
        4. Decoding
        5. For more information
      2. Format
        1. Old style with
        2. New style with
      3. Match with regular expressions
        1. Exact match with
        2. First match with
        3. All matches with
        4. Split at matches with
        5. Replace at matches with
        6. Patterns: special characters
        7. Patterns: specifiers
        8. Patterns: match output
    2. Binary data
      1. and
      2. Other binary data tools
      3. Convert bytes/strings with
      4. Bit operators
    3. Things to do
  9. 8. Data has to go somewhere
    1. File I/O
      1. Write a text file with
      2. Read a text file with
      3. Write a binary file with
      4. Read a binary file with
      5. Close files automatically using
      6. Change position with
    2. Structured text files
      1. CSV
      2. XML
      3. JSON
      4. YAML
      5. A security note
      6. Configuration files
      7. Other interchange formats
      8. Serialize with
    3. Structured binary files
      1. Spreadsheets
      2. HDF5
    4. Relational databases
      1. SQL
      2. DB-API
      3. SQLite
      4. MySQL
      5. PostgreSQL
      6. SQLAlchemy
        1. The engine layer
        2. The SQL Expression Language
        3. The Object-Relational Mapper (ORM)
    5. NoSQL data stores
      1. The
      2. Memcached
      3. Redis
        1. Strings
        2. Lists
        3. Hashes
        4. Sets
        5. Sorted sets
        6. Bits
        7. Caches and expiration
      4. Other NoSQL
    6. Full text databases
    7. Things to do
  10. 9. The web, untangled
    1. Web clients
      1. Test with
      2. Python’s standard web libraries
      3. Beyond the standard library:
    2. Web servers
      1. The simplest Python web server
      2. WSGI
      3. Frameworks
      4. Bottle
      5. Flask
        1. As part of the URL path
      6. Non-Python web servers
        1. Apache
        2. Nginx
      7. Other frameworks
        1. Other Python web servers
    3. Web services and automation
      1. Web APIs and REST
      2. JSON
      3. Crawl and scrape
      4. Scrape HTML with BeautifulSoup
    4. Things to do
  11. 10. Systems
    1. Files
      1. Create with
      2. Check existence with
      3. Check type with
      4. Copy with
      5. Change name with
      6. Link with
      7. Change permissions with
      8. Change ownership with
      9. Get a pathname with
      10. Get a symlink pathname with
      11. Delete a file with
    2. Directories
      1. Create with
      2. Delete with
      3. List contents with
      4. Change current directory with
      5. List matching files with
    3. Programs and processes
      1. Create a process with
      2. Create a process with
      3. Kill a process with
    4. Calendars and clocks
      1. Read and write dates and times
      2. Alternative modules
    5. Things to do
  12. 11. Concurrency and networks
    1. Concurrency
      1. Queues
      2. Processes
      3. Threads
      4. Green threads and
      5. Redis
      6. Issues
    2. Networks
      1. Patterns
      2. Publish-subscribe
        1. Redis
        2. ZeroMQ
        3. Other
      3. TCP/IP
      4. Sockets
      5. ZeroMQ
      6. Scapy
      7. Internet services
        1. DNS
        2. Email
        3. Other protocols
      8. Web services and APIs
      9. Remote processing
        1. RPCs
        2. Salt
      10. Big fat data and map-reduce
      11. Clouds
        1. Google
        2. Amazon
        3. OpenStack
    3. Things to do
  13. 12. Be a pythonista
    1. About Programming
    2. Find Python Code
    3. Install Packages
      1. Use
      2. Use a Package Manager
      3. Install From Source
    4. IDEs
      1. IDLE
      2. PyCharm
      3. IPython
    5. Testing
      1. Check With
      2. Test with
      3. Test with
      4. Test with
      5. Other test frameworks
      6. Continuous Integration
    6. Debug
    7. Log
    8. Optimize
      1. Measure timing
      2. Algorithms and data structures
      3. Cython, NumPy, and C Extensions
      4. PyPy
    9. Source Control
      1. Mercurial
      2. Git
    10. Name and Document
    11. Learn more
      1. Books
      2. Sites
      3. Groups
      4. Conferences
    12. Coming attractions
  14. A. Py art
    1. 2D Graphics
      1. Standard library
      2. PIL and Pillow
      3. ImageMagick
    2. Graphic User Interfaces (GUIs)
    3. 3D graphics and animation
    4. Plots, graphs, visualization
    5. Games
    6. Audio and music
  15. B. Py at work
    1. Office
    2. Business
    3. Data
      1. ETL
      2. Sources
    4. Finance
    5. Security
    6. Maps
      1. Formats
      2. Draw a map
      3. Applications and data
  16. C. Py sci
    1. Math and Statistics in the Standard Library
      1. Math functions
      2. Complex numbers
      3. Accurate floating point with
      4. Rational arithmetic with
      5. Packed sequences with
      6. Simple stats with
      7. Matrix multiplication
    2. Scientific Python
    3. NumPy
      1. Make an array with
      2. Make an array with
      3. Make an array with
      4. Change an array’s shape with
      5. Get an element with
      6. Array math
      7. Linear algebra
    4. SciPy
    5. SciKit
    6. IPython
      1. A better interpreter
      2. IPython Notebook
    7. Pandas
    8. Python and scientific areas
  17. D. Install Python 3
    1. Install standard Python
      1. Mac OS X
      2. Windows
      3. Linux or Unix
    2. Install Anaconda
    3. Install and use
    4. Install and use
  18. E. Answers to exercises
  19. F. Cheatsheets
    1. Operator precedence
    2. String methods
      1. Change case
      2. Search
      3. Modify
      4. Format
      5. String type
    3. module attributes
    4. Fin
  20. About the Author
  21. Copyright