Python object oriented programming fourth edition

Python Object-Oriented Programming- Fourth Edition

Object-oriented programming (OOP) is a popular design paradigm in which data and behaviors are encapsulated in such a way that they can be manipulated together. Python Object-Oriented Programming, Fourth Edition dives deep into the various aspects of OOP, Python as an OOP language, common and advanced design patterns, and hands-on data manipulation and testing of more complex OOP systems. These concepts are consolidated by open-ended exercises, as well as a real-world case study at the end of every chapter, newly written for this edition. All example code is now compatible with Python 3.9+ syntax and has been updated with type hints for ease of learning.

Steven and Dusty provide a comprehensive, illustrative tour of important OOP concepts, such as inheritance, composition, and polymorphism, and explain how they work together with Python’s classes and data structures to facilitate good design. In addition, the book also features an in-depth look at Python’s exception handling and how functional programming intersects with OOP. Two very powerful automated testing systems, unittest and pytest, are introduced. The final chapter provides a detailed discussion of Python’s concurrent programming ecosystem.

By the end of the book, you will have a thorough understanding of how to think about and apply object-oriented principles using Python syntax and be able to confidently create robust and reliable programs.

What you will learn

  • Implement objects in Python by creating classes and defining methods
  • Extend class functionality using inheritance
  • Use exceptions to handle unusual situations cleanly
  • Understand when to use object-oriented features, and more importantly, when not to use them
  • Discover several widely used design patterns and how they are implemented in Python
  • Uncover the simplicity of unit and integration testing and understand why they are so important
  • Learn to statically type check your dynamic code
  • Understand concurrency with asyncio and how it speeds up programs

Who this book is for

If you are new to object-oriented programming techniques, or if you have basic Python skills and wish to learn how and when to correctly apply OOP principles in Python, this is the book for you. Moreover, if you are an object-oriented programmer coming from other languages or seeking a leg up in the new world of Python, you will find this book a useful introduction to Python. Minimal previous experience with Python is necessary.

Источник

Python Object-Oriented Programming. 4th Ed

A knowledge of data structures and the algorithms that bring them to life is the key to building successful data applications. With this knowledge, we have a powerful way to unlock the secrets buried in large amounts of data. This skill is becoming more important in a data-saturated world, where the amount of data being produced dwarfs our ability to analyze it. In this book, you will learn the essential Python data structures and the most common algorithms. This book will provide basic knowledge of Python and an insight into the exciting world of data algorithms. We will look at algorithms that provide solutions to the most common problems in data analysis, including sorting and searching data, as well as being able to extract important statistics from data. With this easy-to-read book, you will learn how to create complex data structures such as linked lists, stacks, and queues, as well as sorting algorithms such as bubble sort and insertion sort. You will learn the common techniques and structures used in tasks such as preprocessing, modeling, and transforming data. We will also discuss how to organize your code in a manageable, consistent, and extendable way. You will learn how to build components that are easy to understand, debug, and use in different applications.

Читайте также:  Two pointers algorithm python

A good understanding of data structures and algorithms cannot be overemphasized. It is an important arsenal to have in being able to understand new problems and find elegant solutions to them. By gaining a deeper understanding of algorithms and data structures, you may find uses for them in many more ways than originally intended. You will develop a consideration for the code you write and how it affects the amount of memory and CPU cycles to say the least. Code will not be written for the sake of it, but rather with a mindset to do more using minimal resources. When programs that have been thoroughly analyzed and scrutinized are used in a real-life setting, the performance is a delight to experience. Sloppy code is always a recipe for poor performance. Whether you like algorithms purely from the standpoint of them being an intellectual exercise or them serving as a source of inspiration in solving a problem, it is an engagement worthy of pursuit.

The Python language has further opened the door for many professionals and students to come to appreciate programming. The language is fun to work with and concise in its description of problems. We leverage the language’s mass appeal to examine a number of widely studied and standardized data structures and algorithms.

The book begins with a concise tour of the Python programming language. As such, it is not required that you know Python before picking up this book.

Если вам понравилась эта книга поделитесь ею с друзьями, тем самым вы помогаете нам развиваться и добавлять всё больше интересных и нужным вам книг!

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Code Repository for Python Object-Oriented Programming — 4th edition, Published by Packt

License

PacktPublishing/Python-Object-Oriented-Programming—4th-edition

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Читайте также:  No print screen html

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Code Repository for Python Object-Oriented Programming — 4th edition, Published by Packt

The case study relies on a number of external packages. It’s often best to start with a tool like conda to build virtual environments and download packages. This can also be done with other virtual environment managers.

The following steps will help you build a working Python environment. Later, we’ll add the additional packages used by the case study.

  1. Get miniconda. Find it here: https://docs.conda.io/en/latest/miniconda.html.
  2. Install miniconda. Find the instructions here: https://conda.io/projects/conda/en/latest/user-guide/install/index.html. For the most part, the instructions can be summarized as «double-click the installer.» There are potential complications, so it can help to read through the the instructions.
  3. Use the conda tool to create a virtual environment that has Python. We’ll add the required packages for this case study.
% conda create -n CaseStudy python=3.9 % conda activate CaseStudy
% python >>> print("Hello, world!") Hello, world! >>> exit()

Installing Other Components

Now that you have a working Python environment, we can add some of packages we’ll be using.

% conda install bs4 pytest pillow

This will ask if you want to proceed. The answer is «y», for «yes.» It will then download and install the four packages listed above, plus the packages they depend on.

Not every package can be installed by conda, so PIP is sometimes needed. Specifically, we want to automate our testing with the tox tool, which isn’t easily installed by conda.

The file environment.yml has the exported environment used to produce this example.

Once PIP has been run, conda can lose track of the extra installations. To make changes, it’s often helpful to create a new conda environment with the packages available from conda, and then add PIP packages.

Your versions may be slightly newer than the ones used by the author.

Multiple Python Version Setup

The full test suite requires multiple versions of Python and the tox utility.

The easiest way to do this is to create an additional conda environment,

conda create --name=tox-py38 python=3.8

This environment will have the needed Python run-time.

For Windows, only, edit the python3.8.bat file to point to this environment’s executables. Generally, the name supplied will be correct.

The test suite requires tox and Python 3.8 (see above for additional installs.)

Use the following command to run all of the tests.

To run tests for a specific chapter, you can change the working director and run tox . Here’s an exception for Chapter 2.

This will change to the chapter 2 directory, ch_02 , and run tox in that directory.

C:\path\to\repo> cmd /c "CHDIR ch_02&&tox"

An Integrated Development Environment

You can edit Python code with any text editor. It can be easier to use a sophisticated IDE, but some developers are happy with simple text editors. There’s no «best» IDE for Python. While the author uses PyCharm and Komodo Edit, some people prefer VS Code, or Spyder.

Good UML diagrams can be created with the http://draw.io diagram editor. This creates drawio text files that can saved as part of a project. It can export PNG files for publication. This is very easy to install and use.

Another choice is to use plantuml. See https://plantuml.com. This can be incorporated into a markdown processing plug-in used by the PyCharm IDE. The plugin depends on graphviz, making the installation fairly complex.

  • Add the Markdown tool to PyCharm.
  • In the preferences for Markdown, install and enable PlantUML.
  • Use conda to install graphviz as well as installing the plantuml-markdown tools. The markdown_py application can create an HTML draft of a Markdown doc. It needs to be installed separately, if this is needed.
  • Update the OS environment settings to set the GRAPHVIZ_DOT environment variable to name the conda virtual environment. where graphviz was installed. The macOS and Linux users should update their ~/.zshrc or ~/.bashrc file, depending on which shell is in use. Windows users should set their system environment variables.
  • It may be necessary to create a plantuml shell script in /usr/local/bin . See https://github.com/mikitex70/plantuml-markdown for details on installation.

The plantuml can be used to tranform UML files to PNG images.

Each chapter’s code is in a separate directory, ch_01 , ch_02 , etc.

Within the chapter, there’s some combination of docs , src , and tests folders. There will also be a pyproject.toml file with parameters used to control tools like tox.

Chapters and Case Study Content

  1. Object-Oriented Design. Creating the 4+1 views of the problem domain.
  2. Objects in Python. Core data model of samples and training data.
  3. When Objects Are Alike. Algorithm Alternatives for k-NN — euclidean, manhattan, chebyshev, minkowski
  4. Expecting the Unexpected. Central authentication and authorization for a web service.
  5. When to Use Object-Oriented Programming. Input validations for training data as well as requests. Properties. Context Managers.
  6. Abstract Base Classes (abc’s) and Operator Overloading. Filtering and subsetting the training data to create test sets. Shuffling. Sorting. Random Selection. Filters.
  7. Python Data Structures. The @dataclass definitions and NamedTuple implementation choices.
  8. Functional Techniques. The essential k-NN algorithm as a functional design. Computing test results for different K values and distance algorithms.
  9. Strings and Serialization. JSON serialization and deserialization of training data, requests and responses.
  10. The Iterator Pattern. Revisiting the k-NN design to permit future flexibility.
  11. Common Design Patterns. (No case study.)
  12. Advanced Design Patterns. (No case study.)
  13. Testing Object-Oriented Programs. Using Test-Driven Develoment on a small ciphering algorithm.
  14. Concurrency. Compressing image files using Run-Length Encoding.

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

About

Code Repository for Python Object-Oriented Programming — 4th edition, Published by Packt

Источник

Оцените статью