Movatterモバイル変換


[0]ホーム

URL:


Packt
Search iconClose icon
Search icon CANCEL
Subscription
0
Cart icon
Your Cart(0 item)
Close icon
You have no products in your basket yet
Save more on your purchases!discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Profile icon
Account
Close icon

Change country

Modal Close icon
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timerSALE ENDS IN
0Days
:
00Hours
:
00Minutes
:
00Seconds
Home> Programming> Object Oriented Programming> Mastering Object-oriented Python
Mastering Object-oriented Python
Mastering Object-oriented Python

Mastering Object-oriented Python: If you want to master object-oriented Python programming this book is a must-have. With 750 code samples and a relaxed tutorial, it's a seamless route to programming Python.

Arrow left icon
Profile Icon Steven F. LottProfile Icon Steven F. Lott
Arrow right icon
$8.98$28.99
Full star iconFull star iconFull star iconFull star iconHalf star icon4.2(13 Ratings)
eBookApr 2014634 pages Edition
eBook
$8.98 $28.99
Paperback
$37.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Steven F. LottProfile Icon Steven F. Lott
Arrow right icon
$8.98$28.99
Full star iconFull star iconFull star iconFull star iconHalf star icon4.2(13 Ratings)
eBookApr 2014634 pages Edition
eBook
$8.98 $28.99
Paperback
$37.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
$8.98 $28.99
Paperback
$37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Table of content iconView table of contentsPreview book icon Preview Book

Mastering Object-oriented Python

Chapter 2. Integrating Seamlessly with Python Basic Special Methods

There are a number of special methods that permit close integration between our classes and Python.Standard Library Reference calls thembasic. A better term might befoundational oressential. These special methods form a foundation for building classes that seamlesslyintegrate with other Python features.

For example, weneed string representations of a given object's value. The base class,object, has a default implementation of__repr__() and__str__() that provides string representations of an object. Sadly, these default representations are remarkably uninformative. We'll almost always want to override one or both of these default definitions. We'll also look at__format__(), which is a bit more sophisticated but serves the same purpose.

We'll also look at other conversions, specifically__hash__(),__bool__(), and__bytes__(). These methods will convert an object into a number, a true/false value, or a string of bytes...

The __repr__() and __str__() methods


Python hastwo string representations of an object. These areclosely aligned with the built-in functionsrepr(),str(),print(), and thestring.format() method.

  • Generally, thestr() method representation of an object is commonly expected to be more friendly to humans. This is built by an object's__str__() method.

  • Therepr() method representation is often going to be more technical, perhaps even a complete Python expression to rebuild the object. The documentation says:

    For many types, this function makes an attempt to return a string that would yield an object with the same value when passed toeval().

    This is built by an object's__repr__() method.

  • Theprint() function will usestr() to prepare an object for printing.

  • Theformat() method of a string can also access these methods. When we use{!r} or{!s} formatting, we're requesting__repr__() or__str__(), respectively.

Let's look at the default implementations first.

The following is a simple class hierarchy...

The __format__() method


The__format__() method is used bystring.format() as well as theformat() built-in function. Bothof these interfaces are used to get presentable string versions of a given object.

Thefollowing are the two ways in which arguments will be presented to__format__():

  • someobject.__format__(""): This happens when the application doesformat(someobject) or something equivalent to"{0}".format(someobject). In these cases, a zero-length string specification was provided. This should produce a default format.

  • someobject.__format__(specification): This happens when the application doesformat(someobject, specification) or something equivalent to"{0:specification}".format(someobject).

Note that something equivalent to"{0!r}".format() or"{0!s}".format() doesn't use the__format__() method. These use__repr__() or__str__() directly.

With a specification of"", a sensible response isreturn str(self). This provides an obvious consistency between the various string representations...

The __hash__() method


The built-inhash() function invokes the__hash__() method of a given object. This hash is a calculation which reduces a (potentially complex) value to a small integer value. Ideally, a hash reflects all the bits of the source value. Other hash calculations—often used for cryptographic purposes—can produce very large values.

Python includes two hash libraries. The cryptographic-quality hash functions are inhashlib. Thezlib module has two high-speed hash functions:adler32() andcrc32(). For relatively simple values, we don't use either of these. For large, complex values, these algorithms can be of help.

Thehash() function (and the associated__hash__() method) is used to create a small integer key that is used to work with collections such asset,frozenset, anddict. These collections use the hash value of animmutable object to rapidly locate the object in the collection.

Immutability is important here; we'll mention it many times. Immutable objects don't change...

The __bool__() method


Python has apleasant definition of falsity. The reference manual lists a large number of values that will test as equivalent toFalse. This includes things such asFalse,0,'',(),[], and{}. Most other objects will test as equivalent toTrue.

Often, we'll want to check for an object being "not empty" with a simple statement as follows:

if some_object:    process( some_object )

Under the hood, this is the job of thebool() built-in function. This function depends on the__bool__() method of a given object.

The default__bool__() method returnsTrue. We can see this with the following code:

>>> x = object()>>> bool(x)True

For most classes, this is perfectly valid. Most objects are not expected to beFalse. For collections, however, this is not appropriate. An empty collection should be equivalent toFalse. A nonempty collection can returnTrue. We might want to add a method like this to ourDeck objects.

If we're wrapping a list, we might have something...

The __bytes__() method


There are relatively few occasions to transform an object into bytes. We'll look at this in detail inPart 2,Persistence and Serialization.

In the mostcommon situation, an application can create a string representation, and the built-in encoding capabilities of the Python IO classes will be used to transform the string into bytes. This works perfectly for almost all situations. The main exception would be when we're defining a new kind of string. In that case, we'd need to define the encoding of that string.

Thebytes() functiondoes a variety of things, depending on the arguments:

  • bytes(integer): This returns an immutable bytes object with the given number of0x00 values.

  • bytes(string): This will encode the given string into bytes. Additional parameters for encoding and error handling will define the details of the encoding process.

  • bytes(something): This will invokesomething.__bytes__() to create a bytes object. Theencoding or error arguments will not be used here...

The comparison operator methods


Python has sixcomparison operators. These operators havespecial method implementations. According to the documentation, the mapping works as follows:

  • x<y callsx.__lt__(y)

  • x<=y callsx.__le__(y)

  • x==y callsx.__eq__(y)

  • x!=y callsx.__ne__(y)

  • x>y callsx.__gt__(y)

  • x>=y callsx.__ge__(y)

We'll return to comparison operators again when looking at numbers inChapter 7,Creating Numbers.

There's an additional rule regarding what operators are actually implemented that's relevant here. These rules are based on the idea that the object's class on the left defines the required special method. If it doesn't, Python can try an alternative operation by changing the order.

Tip

Here are the two basic rules

First, the operand on the left is checked for an operator implementation:A<B meansA.__lt__(B).

Second, the operand on the right is checked for a reversed operator implementation:A<B meansB.__gt__(A).

The rare exception to this occurs when the...

The __del__() method


The__del__() method has a rather obscure use case.

The intent is to give an object a chance to do any cleanup or finalization just before the object is removed from memory. This use case is handled much more cleanly by context manager objects and thewith statement. This is the subject ofChapter 5,Using Callables and Contexts. Creating a context is much more predictable than dealing with__del__() and the Python garbage collection algorithm.

In the case where a Python object has a related OS resource, the__del__() method is a last chance to cleanly disentangle the resource from the Python application. As examples, a Python object that conceals an open file, a mounted device, or perhaps a child subprocess might all benefit from having the resource released as part of__del__() processing.

The__del__() method is not invoked at any easy-to-predict time. It's not always invoked when the object is deleted by adel statement, nor is it always invoked when an object is deleted...

The __new__() method and immutable objects


One usecase for the__new__() method is to initialize objects that are otherwise immutable. The__new__() method is where our code can build an uninitialized object. Thisallows processing before the__init__() method is called to set the attribute values of the object.

The__new__() method is used to extend the immutable classes where the__init__() method can't easily be overridden.

The following is a class that does not work. We'll define a version offloat that carries around information on units:

class Float_Fail( float ):    def __init__( self, value, unit ):        super().__init__( value )        self.unit = unit

We're trying (improperly) to initialize an immutable object.

The following is what happens when we try to use this class definition:

>>> s2 = Float_Fail( 6.5, "knots" )Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: float() takes at most 1 argument (2 given)

From this, we see...

The __new__() method and metaclasses


The other use case for the__new__() method as a part of a metaclass is to control how a classdefinition is built. This is distinct from how__new__() controls building an immutable object, shown previously.

A metaclass builds a class. Once a class object has been built, the class object is used to build instances. The metaclass of all class definitions istype. Thetype() function is used to create class objects.

Additionally, thetype() function can be used as a function to reveal the class of an object.

The following is a silly example of building a new, nearly useless class directly withtype() as a constructor:

Useless= type("Useless",(),{})

Once we've created this class, we can create objects of thisUseless class. However, they won't do much because they have no methods or attributes.

We can use this newly-mintedUseless class to create objects, for what little it's worth. The following is an example:

>>> Useless()<__main__.Useless object...

Summary


We've looked at a number ofbasic special methods, which are essential features of any class that we design. These methods are already part of every class, but the defaults we inherit from the object may not match our processing requirements.

We'll almost always have a need to override__repr__(),__str__(), and__format__(). The default implementations of these methods aren't very helpful at all.

We rarely need to override__bool__() unless we're writing our own collection. That's the subject ofChapter 6,Creating Containers and Collections.

We often need to override the comparison and__hash__() methods. The definitions are suitable for simple immutable objects but not at all appropriate for mutable objects. We may not need to write all the comparison operators; we'll look at the@functools.total_ordering decorator inChapter 8,Decorators and Mixins – Cross-cutting Aspects.

The other twobasic special method names,__new__() and__del__(), are for more specialized purposes. Using...

Left arrow icon

Page1 of 11

Right arrow icon
Download code iconDownload Code

What you will learn

  • Create applications with flexible logging, powerful configuration and commandline options, automated unit tests, and good documentation
  • Get to grips with different design patterns for the __init__() method
  • Design callable objects and context managers
  • Perform object serialization in formats such as JSON, YAML, Pickle, CSV, and XML
  • Map Python objects to a SQL database using the builtin SQLite module
  • Transmit Python objects via RESTful web services
  • Devise strategies for automated unit testing, including how to use the doctest and the unittest.mock module
  • Parse commandline arguments and integrate this with configuration files and environment variables

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date :Apr 22, 2014
Length:634 pages
Edition :
Language :English
ISBN-13 :9781783280988
Category :
Languages :

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Product Details

Publication date :Apr 22, 2014
Length:634 pages
Edition :
Language :English
ISBN-13 :9781783280988
Category :
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99billed monthly
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconSimple pricing, no contract
€189.99billed annually
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick iconExclusive print discounts
€264.99billed in 18 months
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick iconExclusive print discounts

Frequently bought together


Python Data Analysis
Python Data Analysis
Read more
Oct 2014348 pages
Full star icon3.9 (16)
eBook
eBook
$8.98$32.99
$41.99
Python 3 Object Oriented Programming
Python 3 Object Oriented Programming
Read more
Jul 2010404 pages
Full star icon4.6 (54)
eBook
eBook
$8.98$32.99
$41.99
Mastering Object-oriented Python
Mastering Object-oriented Python
Read more
Apr 2014634 pages
Full star icon4.2 (13)
eBook
eBook
$8.98$28.99
$37.99
Stars icon
Total$121.97
Python Data Analysis
$41.99
Python 3 Object Oriented Programming
$41.99
Mastering Object-oriented Python
$37.99
Total$121.97Stars icon
Buy 2+ to unlock€6.99 prices - master what's next.
SHOP NOW

Table of Contents

18 Chapters
The __init__() MethodChevron down iconChevron up icon
The __init__() Method
The implicit superclass – object
The base class object __init__() method
Implementing __init__() in a superclass
Using __init__() to create manifest constants
Leveraging __init__() via a factory function
Implementing __init__() in each subclass
Simple composite objects
Complex composite objects
Stateless objects without __init__()
Some additional class definitions
Multi-strategy __init__()
Yet more __init__() techniques
Summary
Integrating Seamlessly with Python Basic Special MethodsChevron down iconChevron up icon
Integrating Seamlessly with Python Basic Special Methods
The __repr__() and __str__() methods
The __format__() method
The __hash__() method
The __bool__() method
The __bytes__() method
The comparison operator methods
The __del__() method
The __new__() method and immutable objects
The __new__() method and metaclasses
Summary
Attribute Access, Properties, and DescriptorsChevron down iconChevron up icon
Attribute Access, Properties, and Descriptors
Basic attribute processing
Creating properties
Using special methods for attribute access
The __getattribute__() method
Creating descriptors
Summary, design considerations, and trade-offs
The ABCs of Consistent DesignChevron down iconChevron up icon
The ABCs of Consistent Design
Abstract base classes
Base classes and polymorphism
Callables
Containers and collections
Numbers
Some additional abstractions
The abc module
Summary, design considerations, and trade-offs
Using Callables and ContextsChevron down iconChevron up icon
Using Callables and Contexts
Designing with ABC callables
Improving performance
Using functools for memoization
Complexities and the callable API
Managing contexts and the with statement
Defining the __enter__() and __exit__() methods
Context manager as a factory
Summary
Creating Containers and CollectionsChevron down iconChevron up icon
Creating Containers and Collections
ABCs of collections
Examples of special methods
Using the standard library extensions
Creating new kinds of collections
Defining a new kind of sequence
Creating a new kind of mapping
Creating a new kind of set
Summary
Creating NumbersChevron down iconChevron up icon
Creating Numbers
ABCs of numbers
The arithmetic operator's special methods
Creating a numeric class
Computing a numeric hash
Implementing other special methods
Optimization with the in-place operators
Summary
Decorators and Mixins – Cross-cutting AspectsChevron down iconChevron up icon
Decorators and Mixins – Cross-cutting Aspects
Class and meaning
Using built-in decorators
Using standard library mixin classes
Writing a simple function decorator
Parameterizing a decorator
Creating a method function decorator
Creating a class decorator
Adding method functions to a class
Using decorators for security
Summary
Serializing and Saving – JSON, YAML, Pickle, CSV, and XMLChevron down iconChevron up icon
Serializing and Saving – JSON, YAML, Pickle, CSV, and XML
Understanding persistence, class, state, and representation
Filesystem and network considerations
Defining classes to support persistence
Dumping and loading with JSON
Dumping and loading with YAML
Dumping and loading with pickle
Dumping and loading with CSV
Dumping and loading with XML
Summary
Storing and Retrieving Objects via ShelveChevron down iconChevron up icon
Storing and Retrieving Objects via Shelve
Analyzing persistent object use cases
Creating a shelf
Designing shelvable objects
Searching, scanning, and querying
Designing an access layer for shelve
Creating indexes to improve efficiency
Adding yet more index maintenance
The writeback alternative to index updates
Summary
Storing and Retrieving Objects via SQLiteChevron down iconChevron up icon
Storing and Retrieving Objects via SQLite
SQL databases, persistence, and objects
Processing application data with SQL
Mapping Python objects to SQLite BLOB columns
Mapping Python objects to database rows manually
Improving performance with indices
Adding an ORM layer
Querying post objects given a tag string
Improving performance with indices
Summary
Transmitting and Sharing ObjectsChevron down iconChevron up icon
Transmitting and Sharing Objects
Class, state, and representation
Using HTTP and REST to transmit objects
Implementing a REST server – WSGI and mod_wsgi
Using Callable classes for WSGI applications
Creating a secure REST service
Implementing REST with a web application framework
Using a message queue to transmit objects
Summary
Configuration Files and PersistenceChevron down iconChevron up icon
Configuration Files and Persistence
Configuration file use cases
Representation, persistence, state, and usability
Storing the configuration in the INI files
Handling more literals via the eval() variants
Storing the configuration in PY files
Why is exec() a nonproblem?
Using ChainMap for defaults and overrides
Storing the configuration in JSON or YAML files
Storing the configuration in property files
Storing the configuration in XML files – PLIST and others
Summary
The Logging and Warning ModulesChevron down iconChevron up icon
The Logging and Warning Modules
Creating a basic log
Configuration gotcha
Specializing logging for control, debug, audit, and security
Using the warnings module
Advanced logging – the last few messages and network destinations
Summary
Designing for TestabilityChevron down iconChevron up icon
Designing for Testability
Defining and isolating units for testing
Using doctest to define test cases
Using setup and teardown
The TestCase class hierarchy
Using externally defined expected results
Automated integration or performance testing
Summary
Coping With the Command LineChevron down iconChevron up icon
Coping With the Command Line
The OS interface and the command line
Parsing the command line with argparse
Integrating command-line options and environment variables
Customizing the help output
Creating a top-level main() function
Programming In The Large
Additional composite command design patterns
Integrating with other applications
Summary
The Module and Package DesignChevron down iconChevron up icon
The Module and Package Design
Designing a module
Whole module versus module items
Designing a package
Designing a main script and the __main__ module
Designing long-running applications
Organizing code into src, bin, and test
Installing Python modules
Summary
Quality and DocumentationChevron down iconChevron up icon
Quality and Documentation
Writing docstrings for the help() function
Using pydoc for documentation
Better output via the RST markup
Writing effective docstrings
Writing file-level docstrings, including modules and packages
More sophisticated markup techniques
Using Sphinx to produce the documentation
Writing the documentation
Literate programming
Summary

Recommendations for you

Left arrow icon
The C++ Programmer's Mindset
The C++ Programmer's Mindset
Read more
Nov 2025398 pages
eBook
eBook
$8.98$29.99
$37.99
Bare-Metal Embedded C Programming
Bare-Metal Embedded C Programming
Read more
Sep 2024448 pages
Full star icon5 (2)
eBook
eBook
$8.98$25.99
$31.99
Asynchronous Programming in Python
Asynchronous Programming in Python
Read more
Nov 2025202 pages
eBook
eBook
$8.98$26.99
$33.99
Architecting AI Software Systems
Architecting AI Software Systems
Read more
Oct 2025212 pages
Full star icon5 (2)
eBook
eBook
$8.98$26.99
$33.99
Modern C++ Programming Cookbook
Modern C++ Programming Cookbook
Read more
Feb 2024816 pages
Full star icon4.6 (20)
eBook
eBook
$8.98$32.99
$41.99
GPU Programming with C++ and CUDA
GPU Programming with C++ and CUDA
Read more
Aug 2025270 pages
eBook
eBook
$8.98$26.99
$33.99
Learning Zig
Learning Zig
Read more
Nov 2025502 pages
eBook
eBook
$8.98$26.99
$33.99
C++ Memory Management
C++ Memory Management
Read more
Mar 2025442 pages
Full star icon3.7 (3)
eBook
eBook
$8.98$25.99
$31.99
Learn Python Programming
Learn Python Programming
Read more
Nov 2024616 pages
Full star icon3.5 (2)
eBook
eBook
$8.98$23.99
$29.99
Domain-Driven Refactoring
Domain-Driven Refactoring
Read more
May 2025324 pages
Full star icon5 (2)
eBook
eBook
$8.98$23.99
$29.99
Right arrow icon

Customer reviews

Top Reviews
Rating distribution
Full star iconFull star iconFull star iconFull star iconHalf star icon4.2
(13 Ratings)
5 star53.8%
4 star23.1%
3 star15.4%
2 star7.7%
1 star0%
Filter icon Filter
Top Reviews

Filter reviews by




DavidJul 01, 2017
Full star iconFull star iconFull star iconFull star iconFull star icon5
A+ thanks!
Amazon Verified reviewAmazon
Z-Car ManSep 10, 2015
Full star iconFull star iconFull star iconFull star iconFull star icon5
Although I have worked in all areas of the software lifecycle I was new to Python a year ago. When I heard I would be programming in Python I brought a number of books aimed at the intermediate Python programmer. These were expensive and verbose, and failed to hit the mark. How you can write over 1000 pages and skimp some of the fundamentals is beyond me. My original “C” book, Kernigan and Richie, was just over 200 pages and to the point. Word processors have a lot to answer for! My exposure to OO has been limited (C# for a few months and not explained well) and some wxPython. With the project I am now working on I felt I needed a good book but not a door stop. After researching quite a bit I came across this book and felt it was worth buying. At nearly 600 pages it is not a small book but Steven Lott has kept it to the point and relevant throughout. Many authors on software related subjects could learn a lot on how to structure a book from him.The book is broken down into three main sections: Pythonic Classes via Special Methods, Persistence and Serialization and Testing, Debugging, Deploying, and Maintaining. This makes it more manageable. My OO skills in Python have grown markedly in a week. Highly recommended.
Amazon Verified reviewAmazon
Amazon CustomerDec 17, 2016
Full star iconFull star iconFull star iconFull star iconFull star icon5
As represented; no problems
Amazon Verified reviewAmazon
Mike DriscollMay 16, 2014
Full star iconFull star iconFull star iconFull star iconFull star icon5
This is one of Packt’s best books and also one of the best advanced Python books I’ve read. Let’s take a few moments to talk about the chapters. The book is based around the concept of casino Blackjack, which is kind of an odd topic for a programming book. Regardless, the author uses it and a few other examples to help demonstrate some fairly advanced topics in Python. The first chapter is all about Python __init__() method. It shows the reader how to use __init__ in a superclass and a factory function. The second chapter jumps into all of Python’s basic special methods, such as __repr__, __format__, __hash__, etc. You will learn a lot about metaprogramming in these first couple of chapters. Also note that this book is for Python 3 only.Chapter 3 digs into attributes, properties and descriptors. You will learn how to use __slots__, create immutable objects and work with “eagerly computer attributes”. Chapters 4-6 are about creating and working with callables, contexts and containers. There is information about memoization, creating custom callables, how to use __enter__ / __exit__, working with the collections module (deque, ChainMap, OrderedDict, etc) and more! Chapter 7 talks about creating your own Number, which was something I’d never considered doing. The author admits that you normally wouldn’t do it either, but he does teach the reader some interesting concepts (numeric hashes and in-place operators). Chapter 8 finishes up Part 1 with information on decorators and mixins.Part 2 is all about persistence and serialization. Chapter 9 focuses on JSON, YAML and Pickle. The author favors YAML, so you’ll see a lot of examples using it in this section. Chapter 10 digs into using Python shelve objects and using CRUD operations in relation to complex objects. Chapter 11 is about SQLite. Chapter 12 goes into details of using Python to create a REST server and create WSGI applications. Chapter 13 rounds out Part 2 by covering configuration files using Python, JSON, YAML and PLIST.The last section of the book covers testing, debugging, deploying and maintaining. It jumps right in with chapter 14′s topics on the logging and warning modules. Chapter 15 details how to create unittests and doctests in Python. Chapter 16 covers working with command line options via argparse and creating a main() function. In chapter 17, we learn how to design modules and packages. The last chapter of the book goes over quality assurance and documentation. You will learn a bit about the RST markup language and Sphinx for creating documentation.I found Part 1 to be the most interesting part of the book. I learned a great deal about how classes work, metaprogramming techniques and the difference between callables and functions. I think the book is worth purchasing just for that section! Part 2 has a lot of interesting items too, although I question the author’s insistence on using YAML over JSON. I also do not understand why PLIST was even covered as a configuration file type. Part 3 seemed a bit rushed to me. The chapters aren’t as detailed nor the examples as interesting. On the other hand, I may be a bit jaded as this section was mostly material that I already knew. Overall, I found this to be one of the best Python books I’ve read in the last few years. I would definitely recommend it to anyone who wants to learn more about Python’s internals, especially Python’s “magic methods”.
Amazon Verified reviewAmazon
Louis P.Mar 14, 2016
Full star iconFull star iconFull star iconFull star iconFull star icon5
Great content on python classes and some other topics (serialization, etc.). I like a book better than having to google every step or search the documentation. I don't use it anymore but it was a great way to make progress with python.
Amazon Verified reviewAmazon
  • Arrow left icon Previous
  • 1
  • 2
  • 3
  • Arrow right icon Next

People who bought this also bought

Left arrow icon
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (64)
eBook
eBook
$8.98$29.99
$37.99
$37.99
Event-Driven Architecture in Golang
Event-Driven Architecture in Golang
Read more
Nov 2022384 pages
Full star icon4.9 (10)
eBook
eBook
$8.98$29.99
$37.99
$33.99
The Python Workshop Second Edition
The Python Workshop Second Edition
Read more
Nov 2022600 pages
Full star icon4.6 (19)
eBook
eBook
$8.98$31.99
$38.99
Template Metaprogramming with C++
Template Metaprogramming with C++
Read more
Aug 2022480 pages
Full star icon4.6 (13)
eBook
eBook
$8.98$28.99
$35.99
Domain-Driven Design with Golang
Domain-Driven Design with Golang
Read more
Dec 2022204 pages
Full star icon4.4 (18)
eBook
eBook
$8.98$26.99
$33.99
Right arrow icon

About the authors

Left arrow icon
Profile icon Steven F. Lott
Steven F. Lott
Steven Lott has been programming since computers were large, expensive, and rare. Working for decades in high tech has given him exposure to a lot of ideas and techniques, some bad, but most are helpful to others. Since the 1990s, Steven has been engaged with Python, crafting an array of indispensable tools and applications. His profound expertise has led him to contribute significantly to Packt Publishing, penning notable titles like "Mastering Object-Oriented," "The Modern Python Cookbook," and "Functional Python Programming." A self-proclaimed technomad, Steven's unconventional lifestyle sees him residing on a boat, often anchored along the vibrant east coast of the US. He tries to live by the words “Don't come home until you have a story.”
Read more
See other products by Steven F. Lott
Profile icon Steven F. Lott
Steven F. Lott
LinkedIn iconGithub icon
Steven Lott has been programming since computers were large, expensive, and rare. Working for decades in high tech has given him exposure to a lot of ideas and techniques, some bad, but most are helpful to others. Since the 1990s, Steven has been engaged with Python, crafting an array of indispensable tools and applications. His profound expertise has led him to contribute significantly to Packt Publishing, penning notable titles like "Mastering Object-Oriented," "The Modern Python Cookbook," and "Functional Python Programming." A self-proclaimed technomad, Steven's unconventional lifestyle sees him residing on a boat, often anchored along the vibrant east coast of the US. He tries to live by the words “Don't come home until you have a story.”
Read more
See other products by Steven F. Lott
Right arrow icon
Getfree access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook?Chevron down iconChevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website?Chevron down iconChevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook?Chevron down iconChevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support?Chevron down iconChevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks?Chevron down iconChevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook?Chevron down iconChevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Create a Free Account To Continue Reading

Modal Close icon
OR
    First name is required.
    Last name is required.

The Password should contain at least :

  • 8 characters
  • 1 uppercase
  • 1 number
Notify me about special offers, personalized product recommendations, and learning tips By signing up for the free trial you will receive emails related to this service, you can unsubscribe at any time
By clicking ‘Create Account’, you are agreeing to ourPrivacy Policy andTerms & Conditions
Already have an account? SIGN IN

Sign in to activate your 7-day free access

Modal Close icon
OR
By redeeming the free trial you will receive emails related to this service, you can unsubscribe at any time.

[8]ページ先頭

©2009-2025 Movatter.jp