Table of Contents
Python How-To - Table of Contents
Return to Python How-To, Python, Python Bibliography, Manning Python Series, Manning Data Science Series, Manning Books Purchased by Cloud Monk, Manning Bibliography, Cloud Monk's Book Purchases, Cloud Monk Library
about this book
about the author
about the cover illustration
1 Developing a pragmatic learning strategy
1.1 Aiming at becoming a pragmatic programmer
Focusing on writing readable Python code
Considering maintainability even before you write any code
1.2 What Python can do well or as well as other languages
1.3 What Python can't do or can't do well
1.4 What you'll learn in this book
Focusing on domain-independent knowledge
Solving problems through synthesis
Part 1 Using built-in data models
2 Processing and formatting strings
2.1 How do I use f-strings for string interpolation and formatting?
Formatting strings before f-strings
Using f-strings to interpolate variables
Using f-strings to interpolate expressions
Applying specifiers to format f-strings
Discussion]]
2.2 How do I convert strings to retrieve the represented data?
Checking whether strings represent alphanumeric values
Evaluating strings to derive their represented data
Discussion]]
2.3 How do I join and split strings?
Joining strings with whitespaces
Joining strings with any delimiters
Splitting strings to create a list of strings
Discussion]]
2.4 What are the essentials of regular expressions?
Using regular expressions in Python
Creating the pattern with a raw string
Understanding the essentials of a search pattern
Dissecting the matches
Discussion]]
2.5 How do I use regular expressions to process texts?
Creating a working pattern to find the matches
Extracting the needed data from the matches
Using named groups for text processing
Discussion]]
3 Using built-in data containers
3.1 How do I choose between lists and tuples?
Using tuples for immutability and using lists for mutability
Using tuples for heterogeneity and using lists for homogeneity
Discussion]]
3.2 How do I sort lists of complicated data using custom functions?
Sorting lists using the default order
Using a built-in function as the sorting key
Using custom functions for more complicated sorting needs
Discussion]]
3.3 How do I build a lightweight data model using named tuples?
Understanding alternative data models
Creating named tuples to hold data
Discussion]]
3.4 How do I access dictionary keys, values, and items?
Using dynamic view objects (keys, values, and items) directly
Being cautious with the KeyError exception
Avoiding KeyError with a hygiene check first: The non-Pythonic way
Using the get method to access a dictionary item
Watching for the setdefault method's side effect
Discussion]]
3.5 When do I use dictionaries and sets instead of lists and tuples?
Taking advantage of the constant lookup efficiency
Understanding hashable and hashing
Discussion]]
3.6 How do I use set operations to check the relationships between lists?
Checking whether a list contains all items of another list
Checking whether a list contains any element of another list
Dealing with multiple set objects
Discussion]]
4.1 How do I retrieve and manipulate subsequences with slice objects?
Taking advantage of the full features of slicing
Not confusing slices with ranges
Using named slice objects to process sequence data
Manipulating list items with slicing operations
Discussion]]
4.2 How do I use positive and negative indexing to retrieve items?
Positive indexing starts from the beginning of the list
Negative indexing starts from the end of the list
Combining positive and negative indices as needed
Discussion]]
4.3 How do I find items in a sequence?
Using the index method to locate the item
Finding substrings in a string
Finding an instance of custom classes in a list
Discussion]]
4.4 How do I unpack a sequence? Beyond tuple unpacking
Unpacking short sequences with one-to-one correspondence
Retrieving consecutive items using the starred expression
Denoting unwanted items with underscores to remove distraction
Discussion]]
4.5 When should I consider data models other than lists and tuples?
Using sets where membership is concerned
Using deques if you care about first-in-first-out
Processing multidimensional data with NumPy and Pandas
Discussion]]
5.1 How do I create common data containers using iterables?
Getting to know iterables and iterators
Using iterables to create built-in data containers
Discussion]]
5.2 What are list, dictionary, and set comprehensions?
Creating lists from iterables using list comprehension
Creating dictionaries from iterables using dictionary comprehension
Creating sets from iterables using set comprehension
Applying a filtering condition
Discussion]]
5.3 How do I improve for-loop iterations with built-in functions?
Enumerating items with enumerate
Chaining multiple iterables with chain
Filtering the iterable with filter
Discussion]]
5.4 Using optional statements within for and while loops
Exiting the loops with the break statement
Skipping an iteration with the continue statement
Using else statements in the for and while loops
Discussion]]
6 Defining user-friendly functions
6.1 How do I set default arguments to make function calls easier?
Calling functions with default arguments
Defining functions with default arguments
Avoiding the pitfall of setting default arguments for mutable parameters
Discussion]]
6.2 How do I set and use the return value in function calls?
Returning a value implicitly or explicitly
Defining functions returning zero, one, or multiple values
Using multiple values returned from a function call
Discussion]]
6.3 How do I use type hints to write understandable functions?
Providing type hinting to variables
Using type hinting in function definitions
Applying advanced type-hinting skills to function definitions
Discussion]]
6.4 How do I increase function flexibility with *args and **kwargs?
Knowing positional and keyword arguments
Accepting a variable number of positional arguments
Accepting a variable number of keyword arguments
Discussion]]
6.5 How do I write proper docstrings for a function?
Examining the basic structure of a function's docstring
Specifying the function's action as the summary
Documenting the parameters and the return value
Specifying any exceptions possibly raised
Discussion]]
7 Using functions beyond the basics
7.1 How do I use lambda functions for small jobs?
Using lambdas to perform a small one-time]] job
Avoiding pitfalls when using lambda functions
Discussion]]
7.2 What are the implications of functions as objects?
Storing functions in a data container
Sending functions as arguments to higher-order functions
Using functions as a return value
Discussion]]
7.3 How do I check functions' performance with decorators?
Decorating a function to show its performance
Dissecting the decorator function
Wrapping to carry over the decorated function's metadata
Discussion]]
7.4 How can I use generator functions as a memory-efficient data provider?
Creating a generator to yield perfect squares
Using generators for their memory efficiency
Using generator expressions where applicable
Discussion]]
7.5 How do I create partial functions to make routine function calls easier?
“Localizing” shared functions to simplify function calls
Creating a partial function to localize a function
Discussion]]
8 Defining user-friendly classes
8.1 How do I define the initialization method for a class?
Demystifying self: The first parameter in __init__
Setting proper arguments in __init__
Specifying all attributes in __init__
Defining class attributes outside the __init__ method
Discussion]]
8.2 When do I define instance, static, and class methods?
Defining instance methods for manipulating individual instances
Defining static methods for utility functionalities
Defining class methods for accessing class-level attributes
Discussion]]
8.3 How do I apply finer access control to a class?
Creating protected methods by using an underscore as the prefix
Creating private methods by using double underscores as the prefix
Creating read-only attributes with the property decorator
Verifying data integrity with a property setter
Discussion]]
8.4 How do I customize string representation for a class?
Overriding __str__ to show meaningful information for an instance
Overriding __repr__ to provide instantiation information
Understanding the differences between __str__ and __repr__
Discussion]]
8.5 Why and how do I create a superclass and subclasses?
Identifying the use scenario of subclasses
Inheriting the superclass's attributes and methods automatically
Overriding the superclass's methods to provide customized behaviors
Creating non-public methods of the superclass
Discussion]]
9 Using classes beyond the basics
9.1 How do I create enumerations?
Avoiding a regular class for enumerations
Using enumerations
Defining methods for the enumeration class
Discussion]]
9.2 How do I use data classes to eliminate boilerplate code?
Creating a data class using the dataclass decorator
Setting default values for the fields
Creating a subclass of an existing data class
Discussion]]
9.3 How do I prepare and process JSON data?
Understanding JSON's data structure
Mapping data types between JSON and Python
Serializing Python data to JSON format
Discussion]]
9.4 How do I create lazy attributes to improve performance?
Identifying the use scenario
Overriding the __getattr_ special method to implement lazy attributes
Implementing a property as a lazy attribute
Discussion]]
9.5 How do I define classes to have distinct concerns?
Analyzing a class
Creating additional classes to isolate the concerns
Discussion]]
Part 4 Manipulating objects and files
10 Fundamentals of objects
10.1 How do I inspect an object's type to improve code flexibility?
Checking an object's type using type
Checking an object's type using isinstance
Checking an object's type generically
Discussion]]
10.2 What's the lifecycle of instance objects?
Being active in applicable namespaces
Discussion]]
Noting the potential problem of a shallow copy
Discussion]]
10.4 How do I access and change a variable in a different scope?
Accessing any variable: The LEGB rule for name lookup
Changing a global variable in a local scope
Changing an enclosing variable
Discussion]]
10.5 What's callability, and what does it imply?
Distinguishing classes from functions
Revisiting the higher-order function map
Using callable as the key argument
Creating decorators as classes
Discussion]]
11 Dealing with files
11.1 How do I read and write files using context management?
Opening and closing files: Context manager
Reading data from a file in different ways
Writing data to a file in different ways
Discussion]]
11.2 How do I deal with tabulated data files?
Reading a CSV file using csv reader
Reading a CSV file that has a header
Discussion]]
11.3 How do I preserve data as files using pickling?
Pickling objects for data preservation
Weighing the pros and cons of pickling
Discussion]]
11.4 How do I manage files on my computer?
Creating a directory and files
Retrieving the list of files of a specific kind
Moving files to a different folder
Copying files to a different folder
Deleting a specific kind of files
Discussion]]
11.5 How do I retrieve file metadata?
Retrieving the filename-related information
Retrieving the file's size and time information
Discussion]]
Part 5 Safeguarding the codebase
12 Logging and exception handling
12.1 How do I monitor my program with logging?
Creating the Logger object to log application events
Using files to store application events
Adding multiple handlers to the logger
Discussion]]
12.2 How do I save log records properly?
Categorizing application events with levels
Setting formats to the handler
Discussion]]
12.3 How do I handle exceptions?
Handling exceptions with try. . .except. . .
Specifying the exception in the except clause
Showing more information about an exception
Discussion]]
12.4 How do I use else and finally clauses in exception handling?
Using else to continue the logic of the code in the try clause
Cleaning up the exception handling with the finally clause
Discussion]]
12.5 How do I raise informative exceptions with custom exception classes?
Raising exceptions with a custom message
Preferring built-in exception classes
Defining custom exception classes
Discussion]]
13.1 How do I spot problems with tracebacks?
Understanding how a traceback is generated
Analyzing a traceback when running code in a console
Analyzing a traceback when running a script
Focusing on the last call in a traceback
Discussion]]
13.2 How do I debug my program interactively?
Activating the debugger with a breakpoint
Stepping into another function
Inspecting pertinent variables
Discussion]]
13.3 How do I test my functions automatically?
Understanding the basis for testing functions
Creating a TestCase subclass for testing functions
Discussion]]
13.4 How do I test a class automatically?
Creating a TestCase subclass for testing a class
Discussion]]
14 Completing a real project
14.1 How do I use a virtual environment for my project?
Understanding the rationale for virtual environments
Creating a virtual environment for each project
Installing packages in the virtual environment
Using virtual environments in Visual Studio Code
Discussion]]
14.1 How do I build the data models for my project?
Identifying the business needs
Creating helper classes and functions
Creating the Task class to address these needs
Discussion]]
14.2 How do I use SQLite as my application's database?
Retrieving records from the database
Saving records to the database
Updating a record in a database
Deleting a record from the database
Discussion]]
14.3 How do I build a web app as the frontend?
Understanding the essential features of streamlit
Understanding the app's interface
Tracking user activities using session state
Organizing your project
Discussion]]
Appendix A Learning Python with REPL in IDLE
Appendix B Managing Python packages with pip
Appendix C Using Jupyter Notebook: A web-based interactive Python editor
Appendix D Integrating version control into your project
Appendix E Preparing your package for public distribution
Fair Use Sources
Python: Python Variables, Python Data Types, Python Control Structures, Python Loops, Python Functions, Python Modules, Python Packages, Python File Handling, Python Errors and Exceptions, Python Classes and Objects, Python Inheritance, Python Polymorphism, Python Encapsulation, Python Abstraction, Python Lists, Python Dictionaries, Python Tuples, Python Sets, Python String Manipulation, Python Regular Expressions, Python Comprehensions, Python Lambda Functions, Python Map, Filter, and Reduce, Python Decorators, Python Generators, Python Context Managers, Python Concurrency with Threads, Python Asynchronous Programming, Python Multiprocessing, Python Networking, Python Database Interaction, Python Debugging, Python Testing and Unit Testing, Python Virtual Environments, Python Package Management, Python Data Analysis, Python Data Visualization, Python Web Scraping, Python Web Development with Flask/Django, Python API Interaction, Python GUI Programming, Python Game Development, Python Security and Cryptography, Python Blockchain Programming, Python Machine Learning, Python Deep Learning, Python Natural Language Processing, Python Computer Vision, Python Robotics, Python Scientific Computing, Python Data Engineering, Python Cloud Computing, Python DevOps Tools, Python Performance Optimization, Python Design Patterns, Python Type Hints, Python Version Control with Git, Python Documentation, Python Internationalization and Localization, Python Accessibility, Python Configurations and Environments, Python Continuous Integration/Continuous Deployment, Python Algorithm Design, Python Problem Solving, Python Code Readability, Python Software Architecture, Python Refactoring, Python Integration with Other Languages, Python Microservices Architecture, Python Serverless Computing, Python Big Data Analysis, Python Internet of Things (IoT), Python Geospatial Analysis, Python Quantum Computing, Python Bioinformatics, Python Ethical Hacking, Python Artificial Intelligence, Python Augmented Reality and Virtual Reality, Python Blockchain Applications, Python Chatbots, Python Voice Assistants, Python Edge Computing, Python Graph Algorithms, Python Social Network Analysis, Python Time Series Analysis, Python Image Processing, Python Audio Processing, Python Video Processing, Python 3D Programming, Python Parallel Computing, Python Event-Driven Programming, Python Reactive Programming.
Variables, Data Types, Control Structures, Loops, Functions, Modules, Packages, File Handling, Errors and Exceptions, Classes and Objects, Inheritance, Polymorphism, Encapsulation, Abstraction, Lists, Dictionaries, Tuples, Sets, String Manipulation, Regular Expressions, Comprehensions, Lambda Functions, Map, Filter, and Reduce, Decorators, Generators, Context Managers, Concurrency with Threads, Asynchronous Programming, Multiprocessing, Networking, Database Interaction, Debugging, Testing and Unit Testing, Virtual Environments, Package Management, Data Analysis, Data Visualization, Web Scraping, Web Development with Flask/Django, API Interaction, GUI Programming, Game Development, Security and Cryptography, Blockchain Programming, Machine Learning, Deep Learning, Natural Language Processing, Computer Vision, Robotics, Scientific Computing, Data Engineering, Cloud Computing, DevOps Tools, Performance Optimization, Design Patterns, Type Hints, Version Control with Git, Documentation, Internationalization and Localization, Accessibility, Configurations and Environments, Continuous Integration/Continuous Deployment, Algorithm Design, Problem Solving, Code Readability, Software Architecture, Refactoring, Integration with Other Languages, Microservices Architecture, Serverless Computing, Big Data Analysis, Internet of Things (IoT), Geospatial Analysis, Quantum Computing, Bioinformatics, Ethical Hacking, Artificial Intelligence, Augmented Reality and Virtual Reality, Blockchain Applications, Chatbots, Voice Assistants, Edge Computing, Graph Algorithms, Social Network Analysis, Time Series Analysis, Image Processing, Audio Processing, Video Processing, 3D Programming, Parallel Computing, Event-Driven Programming, Reactive Programming.
Python Glossary, Python Fundamentals, Python Inventor: Python Language Designer: Guido van Rossum on 20 February 1991; PEPs, Python Scripting, Python Keywords, Python Built-In Data Types, Python Data Structures - Python Algorithms, Python Syntax, Python OOP - Python Design Patterns, Python Module Index, pymotw.com, Python Package Manager (pip-PyPI), Python Virtualization (Conda, Miniconda, Virtualenv, Pipenv, Poetry), Python Interpreter, CPython, Python REPL, Python IDEs (PyCharm, Jupyter Notebook), Python Development Tools, Python Linter, Pythonista-Python User, Python Uses, List of Python Software, Python Popularity, Python Compiler, Python Transpiler, Python DevOps - Python SRE, Python Data Science - Python DataOps, Python Machine Learning, Python Deep Learning, Functional Python, Python Concurrency - Python GIL - Python Async (Asyncio), Python Standard Library, Python Testing (Pytest), Python Libraries (Flask), Python Frameworks (Django), Python History, Python Bibliography, Manning Python Series, Python Official Glossary - Python Glossary, Python Topics, Python Courses, Python Research, Python GitHub, Written in Python, Python Awesome List, Python Versions. (navbar_python - see also navbar_python_libaries, navbar_python_standard_library, navbar_python_virtual_environments, navbar_numpy, navbar_datascience)
© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers
SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.