100% found this document useful (3 votes)
955 views88 pages

Instant download Python Unlocked 1st Edition Arun Tigeraniya pdf all chapter

The document promotes the ebook 'Python Unlocked' by Arun Tigeraniya, available for download along with various other ebooks on ebookgate.com. It outlines the content of 'Python Unlocked', which covers advanced Python programming techniques, including object-oriented programming, design patterns, and optimization strategies. The book is aimed at Python developers looking to deepen their understanding and improve their coding skills.

Uploaded by

soutoguski6v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
955 views88 pages

Instant download Python Unlocked 1st Edition Arun Tigeraniya pdf all chapter

The document promotes the ebook 'Python Unlocked' by Arun Tigeraniya, available for download along with various other ebooks on ebookgate.com. It outlines the content of 'Python Unlocked', which covers advanced Python programming techniques, including object-oriented programming, design patterns, and optimization strategies. The book is aimed at Python developers looking to deepen their understanding and improve their coding skills.

Uploaded by

soutoguski6v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

Get the full ebook with Bonus Features for a Better Reading Experience on ebookgate.

com

Python Unlocked 1st Edition Arun Tigeraniya

https://ebookgate.com/product/python-unlocked-1st-edition-
arun-tigeraniya/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookgate.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Cryptology Unlocked 1st Edition Reinhard Wobst

https://ebookgate.com/product/cryptology-unlocked-1st-edition-
reinhard-wobst/

ebookgate.com

Algorithms Unlocked 1st Edition Thomas H. Cormen

https://ebookgate.com/product/algorithms-unlocked-1st-edition-thomas-
h-cormen/

ebookgate.com

Social Psychology 1st Edition Arun Kumar Singh

https://ebookgate.com/product/social-psychology-1st-edition-arun-
kumar-singh/

ebookgate.com

Diagnostic Radiology 3rd Edition Arun Jamar Gupta (Editor)

https://ebookgate.com/product/diagnostic-radiology-3rd-edition-arun-
jamar-gupta-editor/

ebookgate.com
Management of Fungal Plant Pathogens First Edition Arun
Arya

https://ebookgate.com/product/management-of-fungal-plant-pathogens-
first-edition-arun-arya/

ebookgate.com

A History of Silicon Valley 2nd Edition Arun Rao

https://ebookgate.com/product/a-history-of-silicon-valley-2nd-edition-
arun-rao/

ebookgate.com

Black hat Python Python programming for hackers and


pentesters 1st Edition Seitz

https://ebookgate.com/product/black-hat-python-python-programming-for-
hackers-and-pentesters-1st-edition-seitz/

ebookgate.com

Photoshop CS6 unlocked 101 tips tricks techniques 2nd ed


Edition Haffly

https://ebookgate.com/product/photoshop-cs6-unlocked-101-tips-tricks-
techniques-2nd-ed-edition-haffly/

ebookgate.com

Python The Complete Manual The essential handbook for


Python users Master Python today First Edition Unknown

https://ebookgate.com/product/python-the-complete-manual-the-
essential-handbook-for-python-users-master-python-today-first-edition-
unknown/
ebookgate.com
Table of Contents
Python Unlocked
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Objects in Depth
Understanding objects
Identity
Value
Type
Making calls to objects
How objects are created
Creation of function objects
Creation of instances
Creation of class objects
Playing with attributes
Descriptors
Class, static, and instance methods
Summary
2. Namespaces and Classes
How referencing objects work – namespaces
Functions with state – closures
Understanding import and modules
Customizing imports
Class inheritance
Method resolution order
Super's superpowers
Using language protocols in classes
Iteration protocol
Context manager protocol
Using abstract classes
Summary
3. Functions and Utilities
Defining functions
Decorating callables
Utilities
Summary
4. Data Structures and Algorithms
Python built-in data structures
Python library data structures
Third party data structures
Arrays/List
Binary tree
Sorted containers
Trie
Algorithms on scale
Summary
5. Elegance with Design Patterns
Observer pattern
Strategy pattern
Singleton pattern
Template pattern
Adaptor pattern
Facade pattern
Flyweight pattern
Command pattern
Abstract factory
Registry pattern
State pattern
Summary
6. Test-Driven Development
Mock for tests
Parameterization
Creating custom test runners
Testing threaded applications
Running test cases in parallel
Summary
7. Optimization Techniques
Writing optimized code
Profiling to find bottlenecks
Using fast libraries
Using C speeds
SWIG
CFFI
Cython
Summary
8. Scaling Python
Going multithreaded
Using multiple processes
Going asynchronous
Scaling horizontally
Summary
Index
Python Unlocked
Python Unlocked
Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in


a retrieval system, or transmitted in any form or by any means,
without the prior written permission of the publisher, except in the
case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure
the accuracy of the information presented. However, the information
contained in this book is sold without warranty, either express or
implied. Neither the author, nor Packt Publishing, and its dealers and
distributors will be held liable for any damages caused or alleged to
be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information


about all of the companies and products mentioned in this book by
the appropriate use of capitals. However, Packt Publishing cannot
guarantee the accuracy of this information.

First published: December 2015

Production reference: 1181215

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78588-599-0

www.packtpub.com
Credits
Author

Arun Tigeraniya

Reviewers

Mike Driscoll

Chetan Giridhar

Sanjeev Jaiswal

Vishrut Mehta

Commissioning Editor

Veena Pagare

Acquisition Editor

Vivek Anantharaman

Content Development Editors

Neeshma Ramakrishnan

Deepti Thore

Technical Editor

Vijin Boricha

Copy Editor

Priyanka Ravi
Project Coordinator

Shweta H Birwatkar

Proofreader

Safis Editing

Indexer

Mariammal Chettiyar

Production Coordinator

Arvindkumar Gupta

Cover Work

Arvindkumar Gupta
About the Author
Arun Tigeraniya has a BE in electronics and communication. After
his graduation, he worked at various companies as a Python
developer. His main professional interests are AI and Big Data. He
enjoys writing efficient and testable code, and interesting technical
articles. He has worked with open source technology since 2008. He
currently works at Jaarvis Labs Limited, India.

I would like to thank my parents and elder siblings, Ashok and


Asha, who have always supported me in completing this book
with good quality. A special thanks to the people at Packt for
being so understanding even though I missed a few deadlines.
About the Reviewers
Mike Driscoll has been programming in Python since 2006. He
enjoys writing about Python on his blog at
http://www.blog.pythonlibrary.org/. He co-authored Core Python
Refcard for DZone. Mike has also been a technical reviewer for
Python 3 Object Oriented Programming, Python 2.6 Graphics
Cookbook and Tkinter GUI Application Development Hotshot, all by
Packt Publishing. He recently wrote the book Python 101, and is
working on his next book.

I would like to thank my beautiful wife, Evangeline, for always


supporting me. I would also like to thank my friends and family
for all that they do to help me. Finally, I would like to thank Jesus
Christ for saving me.

Chetan Giridhar is a Python developer, open source enthusiast, and


start-up specialist. He has authored/reviewed books on Python,
published papers in journals, and delivered talks in conferences
around the world. You can get in touch with him at
<[email protected]>.

He has also reviewed IPython Interactive Computing and


Visualization Cookbook by Packt Publishing.

I would like thank my mentors, friends, colleagues, and my ever-


supporting family.

Sanjeev Jaiswal is a computer graduate having 6 years of industrial


experience. He uses Perl, Python, and GNU/Linux for his day-to-day
work. Sanjeev teaches Perl, Python, web development online as
well. Sanjeev has worked closely with major clients, such as CSC,
IBM, United Online, and Syniverse. He has also developed an
interest in web application security since 2013.

Sanjeev loves teaching technical stuff to engineering students and IT


professionals, and he has been teaching since 2008. He founded
Alien Coders (http://www.aliencoders.org/) based on the Learning
through sharing principle for computer science students and IT
professionals in 2010, and it became a huge hit in India amongst
engineering students.

He usually uploads technical videos on YouTube under the


AlienCoders tag. One can follow him on:

Facebook at http://www.facebook.com/jassics
Twitter at http://twitter.com/jassics

He wrote an Instant book called WebSpeed Optimization


Techniques, and Learning Django Web Development by Packt
Publishing, and he is always looking forward to author or review
more and more books from Packt and other publishers.

I would like to thank my parents and my wife, Shalini Jaiswal, for


moral support at every phase of life and growth. I also give deep
thanks and gratitude to my best friends Ritesh Kamal and Ranjan
Pandey for their personal and professional help all the time.

It is because of them and other friends that I learned and


achieved a set of impossible goals in a short time.

Vishrut Mehta is a dual degree student of IIIT Hyderabad, currently


in his 5th year. He is completing his MS under Dr. Vasudeva Varma,
Research Dean of IIIT, at Search and Information Extraction Lab
(SIEL). He works in areas related to software-defined networks and
cloud computing. He completed his internship at Google last summer
and a research internship at INRIA, France, in 2014. During his
internship, he worked on various areas of cloud computing, such as
automatic reconfiguration of a multicloud application. Vishrut also
participated in Google Summer of Code in 2013 and was also was
the admin for the Google Code-in between 2013 and 2014 for
Sahana Software Foundation.

He has also reviewed Learning Python Network Programming,


Untangle Network Security, and Python Network Programming
Cookbook, all by Packt Publishing.

I would like to thank my guides Dr. Vasudeva Varma and Dr.


Reddy Raja for constantly supporting my ideas and helping me in
my work. I would also like to thank my parents who never lost
their faith in me.
www.PacktPub.com
Support files, eBooks, discount
offers, and more
For support files and downloads related to your book, please visit
www.PacktPub.com.

Did you know that Packt offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade to
the eBook version at www.PacktPub.com and as a print book
customer, you are entitled to a discount on the eBook copy. Get in
touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free


technical articles, sign up for a range of free newsletters and receive
exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is


Packt's online digital book library. Here, you can search, access, and
read Packt's entire library of books.

Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can
use this to access PacktLib today and view 9 entirely free books.
Simply use your login credentials for immediate access.
Preface
Python is a versatile programming language that can be used for a
wide range of technical tasks—computation, statistics, data analysis,
game development, and more. Though Python is easy to learn, its
range of features means there are many aspects of it that even
experienced Python developers don't know about. Even if you're
confident with the basics, its logic and syntax, by digging deeper you
can work much more effectively with Python—and get more from the
language.

Python Unlocked walks you through the most effective techniques


and best practices for high performance Python programming—
showing you how to make the most of the Python language. You'll
get to know objects and functions inside and out, and will learn how
to use them to your advantage in your programming projects. You
will also find out how to work with a range of design patterns,
including abstract factory, singleton, and the strategy pattern, all of
which will help make programming with Python much more efficient.
As the process of writing a program is never complete without testing
it, you will learn to test threaded applications and run parallel tests.

If you want the edge when it comes to Python, use this book to
unlock the secrets of smarter Python programming.
What this book covers
Chapter 1, Objects in Depth, discusses object properties, attributes,
creation and how calling objects work.

Chapter 2, Namespaces and Classes, discusses namespaces, how


imports work, class multiple inheritance, MRO, Abstract classes, and
protocols.

Chapter 3, Functions and Utilities, teaches function definitions,


decorators, and some utilities.

Chapter 4, Data Structures and Algorithms, discusses in-built, library,


third party data structures and algorithms.

Chapter 5, Elegance with Design Patterns, covers many important


design patterns.

Chapter 6, Test-Driven Development, discusses mock objects,


parameterization, creating custom test runners, testing threaded
applications, and running testcases in parallel.

Chapter 7, Optimization Techniques, covers optimization techniques,


profiling, using fast libraries, and compiling C modules.

Chapter 8, Scaling Python, covers multithreading, multiprocessing,


asynchronization, and scaling horizontally.
What you need for this book
You should have a working installation of Python, preferably greater
than 3.4. You can use this with Python 2 as well but the book uses
Python 3 and introduces its many new features.
Who this book is for
If you are a Python developer and you think that you do not fully
understand the language, then this book is for you. This book will
unlock mysteries and reintroduce the hidden features of Python to
write efficient programs, making optimal use of the language.
Conventions
In this book, you will find a number of text styles that distinguish
between different kinds of information. Here are some examples of
these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames,


file extensions, pathnames, dummy URLs, user input, and Twitter
handles are shown as follows: "So, we can change an object's type
by changing its __class__ attribute."

A block of code is set as follows:

def __init__(self, name):


self.name = name
self._observers = weakref.WeakSet()

def register_observer(self, observer):


"""attach the observing object for this
subject
"""
self._observers.add(observer)
print("observer {0} now listening on
{1}".format(
observer.name, self.name))

When we wish to draw your attention to a particular part of a code


block, the relevant lines or items are set in bold:

self.assertFalse(assign_if_free(mworker,
{}))

def test_worker_free(self,):
mworker = create_autospec(IWorker)
mworker.configure_mock(**
{'is_busy.return_value':False})
self.assertTrue(assign_if_free(mworker,
{}))
New terms and important words are shown in bold. Words that you
see on the screen, for example, in menus or dialog boxes, appear in
the text like this: "Let's take an example of an object iC instance of
the C class with the str and lst attributes."

Note
Warnings or important notes appear in a box like this.

Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what
you think about this book—what you liked or disliked. Reader
feedback is important for us as it helps us develop titles that you will
really get the most out of.

To send us general feedback, simply e-mail


<[email protected]>, and mention the book's title in the subject
of your message.

If there is a topic that you have expertise in and you are interested in
either writing or contributing to a book, see our author guide at
www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a
number of things to help you to get the most from your purchase.

Downloading the example code


You can download the example code files from your account at
http://www.packtpub.com for all the Packt Publishing books you have
purchased. If you purchased this book elsewhere, you can visit
http://www.packtpub.com/support and register to have the files e-
mailed directly to you.

Errata
Although we have taken every care to ensure the accuracy of our
content, mistakes do happen. If you find a mistake in one of our
books—maybe a mistake in the text or the code—we would be
grateful if you could report this to us. By doing so, you can save
other readers from frustration and help us improve subsequent
versions of this book. If you find any errata, please report them by
visiting http://www.packtpub.com/submit-errata, selecting your book,
clicking on the Errata Submission Form link, and entering the
details of your errata. Once your errata are verified, your submission
will be accepted and the errata will be uploaded to our website or
added to any list of existing errata under the Errata section of that
title.

To view the previously submitted errata, go to


https://www.packtpub.com/books/content/support and enter the
name of the book in the search field. The required information will
appear under the Errata section.

Piracy
Piracy of copyrighted material on the Internet is an ongoing problem
across all media. At Packt, we take the protection of our copyright
and licenses very seriously. If you come across any illegal copies of
our works in any form on the Internet, please provide us with the
location address or website name immediately so that we can
pursue a remedy.

Please contact us at <[email protected]> with a link to the


suspected pirated material.

We appreciate your help in protecting our authors and our ability to


bring you valuable content.

Questions
If you have a problem with any aspect of this book, you can contact
us at <[email protected]>, and we will do our best to address
the problem.
Chapter 1. Objects in Depth
In this chapter, we will dive into Python objects. Objects are the
building blocks of the language. They may represent or abstract a
real entity. We will be more interested in factors affecting such
behavior. This will help us understand and appreciate the language
in a better way. We will cover the following topics:

Object characteristics
Calling objects
How objects are created
Playing with attributes

Understanding objects
Key 1: Objects are language's abstraction for data. Identity,
value, and type are characteristic of them.

All data and items that we work on in a program are objects, such as
numbers, strings, classes, instances, and modules. They possess
some qualities that are similar to real things as all of them are
uniquely identifiable just like humans are identifiable by their DNA.
They have a type that defines what kind of object it is, and the
properties that it supports, just like humans of type cobbler support
repairing shoes, and blacksmiths support making metal items. They
possess some value, such as strength, money, knowledge, and
beauty do for humans.

Name is just a means to identify an object in a namespace similar to


how it is used to identify a person in a group.

Identity
In Python, every object has a unique identity. We can get this identity
by passing an object to built-in ID function ID (object).This returns
the memory address of the object in CPython.

Interpreter can reuse some objects so that the total number of


objects remains low. For example, integers and strings can be
reused in the following manner:

>>> i = "asdf"
>>> j = "asdf"
>>> id(i) == id(j)
True
>>> i = 10000000000000000000000000000000
>>> j = 10000000000000000000000000000000
>>> id(j) == id(i) #cpython 3.5 reuses integers
till 256
False
>>> i = 4
>>> j = 4
>>> id(i) == id(j)
True
>>> class Kls:
... pass
...
>>> k = Kls()
>>> j = Kls()
>>> id(k) == id(j) #always different as id gives
memory address
False

This is also a reason that addition of two strings is a third new string,
and, hence, it is best to use the StringIO module to work with a
buffer, or use the join attribute of strings:

>>> # bad
... print('a' + ' ' + 'simple' + ' ' + 'sentence'
+ ' ' + '')
a simple sentence
>>> #good
... print(' '.join(['a','simple','sentence','.']))
a simple sentence .

Value
Key 2: Immutability is the inability to change an object's value.

The value of the object is the data that is stored in it. Data in an
object can be stored as numbers, strings, or references to other
objects. Strings, and integers are objects themselves. Hence, for
objects that are not implemented in C (or core objects), it is a
reference to other objects, and we perceive value as the group value
of the referenced object. Let's take an example of an object iC
instance of the C class with the str and lst attributes, as shown in
the following diagram:

The code snippet to create this object will be as follows:

>>> class C:
... def __init__(self, arg1, arg2):
... self.str = arg1
... self.lst = arg2
...
>>> iC = C("arun",[1,2])
>>> iC.str
'arun'
>>> iC.lst
[1, 2]
>>> iC.lst.append(4)
>>> iC.lst
[1, 2, 4]

Then, when we modify iC, we are either changing the objects


references via attributes, or we are changing the references
themselves and not the object iC. This is important in understanding
immutable objects because being immutable means not being able
to change references. Hence, we can change mutable objects that
are referenced by immutable objects. For example, lists inside tuple
can be changed because the referenced objects are changing, not
the references.

Type
Key 3: Type is instance's class.

An object's type tells us about the operations and functionality that


the object supports, and it may also define the possible values for
objects of that type. For example, your pet may be of type dog (an
instance of the dog class) or cat (an instance of the cat class). If it is
of type dog, it can bark; and if it is type cat, it can meow. Both are a
type of animal (cat and dog inherit from the animal class).

An object's class provides a type to it. Interpreter gets the object's


class by checking its __class__ attribute. So, we can change an
object's type by changing its __class__ attribute:

>>> k = []
>>> k.__class__
<class 'list'>
>>> type(k)
<class 'list'>
# type is instance's class
>>> class M:
... def __init__(self,d):
... self.d = d
... def square(self):
... return self.d * self.d
...
>>>
>>> class N:
... def __init__(self,d):
... self.d = d
... def cube(self):
... return self.d * self.d * self.d
...
>>>
>>> m = M(4)
>>> type(m) #type is its class
<class '__main__.M'>
>>> m.square() #square defined in class M
16
>>> m.__class__ = N # now type should change
>>> m.cube() # cube in class N
64
>>> type(m)
<class '__main__.N'> # yes type is changed

Note
This will not work for built-in, compiled classes as it works only
for class objects defined on runtime.
Making calls to objects
Key 4: All objects can be made callable.

To reuse and group code for some task, we group it in the functions
classes, and then call it with different inputs. The objects that have a
__call__ attribute are callable and __call__ is the entry point. For the
C class, tp_call is checked in its structure:

>>> def func(): # a function


... print("adf")
...
>>> func()
adf
>>> func.__call__() #implicit call method
adf
>>> func.__class__.__call__(func)
adf
>>> func.__call__
<method-wrapper '__call__' of function object at
0x7ff7d9f24ea0>
>>> class C: #a callable class
... def __call__(self):
... print("adf")
...
>>> c = C()
>>> c()
adf
>>> c.__call__() #implicit passing of self
adf
>>> c.__class__.__call__(c) #explicit passing of
self
adf
>>> callable(lambda x:x+1) #testing whether
object is callable or not
True
>>> isinstance(lambda x:x+1, collections.Callable)
#testing whether object is callable or not
True

Methods in classes are similar to functions, except that they are


called with an implicit instance as a first argument. The functions are
exposed as methods when they are accessed from the instance. The
function is wrapped in a method class and returned. The method
class stores instances in __self__ and function in __func__, and its
__call__ method calls __func__ with first argument as __self__:

>>> class D:
... pass
...
>>> class C:
... def do(self,):
... print("do run",self)
...
>>> def doo(obj):
... print("doo run",obj)
...
>>> c = C()
>>> d = D()
>>> doo(c)
doo run <__main__.C object at 0x7fcf543625c0>
>>> doo(d)
doo run <__main__.D object at 0x7fcf54362400>
>>> # we do not need to pass object in case of C
class do method
...
>>> c.do() #implicit pass of c object to do method
do run <__main__.C object at 0x7fcf543625c0>
>>> C.doo = doo
>>> c.doo()
doo run <__main__.C object at 0x7fcf543625c0>
>>> C.doo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: doo() missing 1 required positional
argument: 'obj'
>>> C.do()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: do() missing 1 required positional
argument: 'self'
>>> C.do(c)
do run <__main__.C object at 0x7fcf543625c0>
>>> C.do(d)
do run <__main__.D object at 0x7fcf54362400>
>>> c.do.__func__(d) #we called real function this
way
do run <__main__.D object at 0x7fcf54362400>
Using this logic, we can also collect methods that are needed from
other classes in the current class, like the following code, instead of
multiple inheritances if data attributes do not clash. This will result in
two dictionary lookups for an attribute search: one for instance, and
one for class.

>>> #in library


... class PrintVals:
... def __init__(self, endl):
... self.endl = endl
...
... def print_D8(self, data):
... print("{0} {1}
{2}".format(data[0],data[1],self.endl))
...
>>> class PrintKVals: #from in2 library
... def __init__(self, knm):
... self.knm = knm
...
... def print_D8(self, data):
... print("{2}:{0}
{1}".format(data[0],data[1],self.knm))
...
>>> class CollectPrint:
...
... def __init__(self, endl):
... self.endl = endl
... self.knm = "[k]"
...
... print_D8 = PrintVals.print_D8
... print_D8K = PrintKVals.print_D8
...
>>> c = CollectPrint("}")
>>> c.print_D8([1,2])
1 2 }
>>> c.print_D8K([1,2])
[k]:1 2

When we call classes, we are calling its type, that is metaclass, with
class as a first argument to give us a new instance:

>>> class Meta(type):


... def __call__(*args):
... print("meta call",args)
...
>>> class C(metaclass=Meta):
... pass
...
>>>
>>> c = C()
meta call (<class '__main__.C'>,)
>>> c = C.__class__.__call__(C)
meta call (<class '__main__.C'>,)

Similarly, when we call instances, we are calling their type, that is


class, with instance as first argument:

>>> class C:
... def __call__(*args):
... print("C call",args)
...
>>> c = C()
>>> c()
C call (<__main__.C object at 0x7f5d70c2bb38>,)
>>> c.__class__.__call__(c)
C call (<__main__.C object at 0x7f5d70c2bb38>,)
How objects are created
Objects other than built-in types or compiled module classes are
created at runtime. Objects can be classes, instances, functions, and
so on. We call an object's type to give us a new instance; or put in
another way, we call a type class to give us an instance of that type.

Creation of function objects


Key 5: Create function on runtime.

Let's first take a look at how function objects can be created. This
will broaden our view. This process is done by interpreter behind the
scenes when it sees a def keyword. It compiles the code, which is
shown as follows, and passes the code name arguments to the
function class that returns an object:

>>> function_class = (lambda x:x).__class__


>>> function_class
<class 'function'>
>>> def foo():
... print("hello world")
...
>>>
>>> def myprint(*args,**kwargs):
... print("this is my print")
... print(*args,**kwargs)
...
>>> newfunc1 = function_class(foo.__code__,
{'print':myprint})
>>> newfunc1()
this is my print
hello world
>>> newfunc2 =
function_class(compile("print('asdf')","filename",
"single"),{'print':print})
>>> newfunc2()
asdf
Creation of instances
Key 6: Process flow for instance creation.

We call class to get a new instance. We saw from the making calls to
objects section that when we call class, it calls its metaclass
__call__ method to get a new instance. It is the responsibility of
__call__ to return a new object that is properly initialized. It is able to
call class's __new__, and __init__ because class is passed as first
argument, and instance is created by this function itself:

>>> class Meta(type):


... def __call__(*args):
... print("meta call ",args)
... return None
...
>>>
>>> class C(metaclass=Meta):
... def __init__(*args):
... print("C init not called",args)
...
>>> c = C() #init will not get called
meta call (<class '__main__.C'>,)
>>> print(c)
None
>>>

To enable developer access to both functionalities, creating new


object, and initializing new object, in class itself; __call__ calls the
__new__ class to return a new object and __init__ to initialize it. The
full flow can be visualized as shown in the following code:

>>> class Meta(type):


... def __call__(*args):
... print("meta call ,class object
:",args)
... class_object = args[0]
... if '__new__' in class_object.__dict__:
... new_method =
getattr(class_object,'__new__',None)
... instance =
new_method(class_object)
... else:
... instance =
object.__new__(class_object)
... if '__init__' in
class_object.__dict__:
... init_method =
getattr(class_object,'__init__',None)
... init_method(instance,*args[1:])
... return instance
...
>>> class C(metaclass=Meta):
... def __init__(instance_object, *args):
... print("class init",args)
... def __new__(*args):
... print("class new",args)
... return object.__new__(*args)
...
>>> class D(metaclass=Meta):
... pass
...
>>> c=C(1,2)
meta call ,class object : (<class '__main__.C'>,
1, 2)
class new (<class '__main__.C'>,)
class init (1, 2)
>>> d = D(1,2)
meta call ,class object : (<class '__main__.D'>,
1, 2)
>>>

Take a look at the following diagram:


Creation of class objects
Key 7: Process flow for class creation.

There are three ways in which we can create classes. One is to


simply define the class. The second one is to use the built-in
__build_class__ function, and the third is to use the new_class
method of type module. Method one uses two, method two uses
method three internally. When interpreter sees a class keyword, it
collects the name, bases, and metaclass that is defined for the class.
It will call the __build_class__ built-in function with function (with the
code object of the class), name of the class, base classes,
metaclass that is defined, and so on:

__build_class__(func, name, *bases,


metaclass=None, **kwds) -> class

This function returns the class. This will call the __prepare__ class
method of metaclass to get a mapping data structure to use as a
namespace. The class body will be evaluated, and local variables
will be stored in this mapping data structure. Metaclass's type will be
called with this namespace dictionary, bases, and class name. It will
in turn call the __new__ and __init__ methods of metaclass.
Metaclass can change attributes passed to its method:

>>> function_class = (lambda x:x).__class__


>>> M = __build_class__(function_class(
... compile("def
__init__(self,):\n print('adf')",
... '<stdin>',
... 'exec'),
... {'print':print}
... ),
... 'MyCls')
>>> m = M()
adf
>>> print(M,m)
<class '__main__.MyCls'> <__main__.MyCls object at
0x0088B430>
>>>

Take a look at the following diagram:


Playing with attributes
Key 8: Which attribute will be used.

Attributes are values that are associated with an object that can be
referenced by name using dotted expressions. It is important to
understand how attributes of an object are found. The following is
the sequence that is used to search an attribute:

1. If an attribute is a special method, and it exists in the object's


type (or bases), return it, for example: __call__, __str__, and
__init__. When these methods are searched, their behavior is
only in the instance's type:
>>> class C:
... def __str__(self,):
... return 'Class String'
... def do(self):
... return 'Class method'
...
>>> c = C()
>>> print(c)
Class String
>>> print(c.do())
Class method
>>> def strf(*args):
... return 'Instance String',args
...
>>> def doo(*args):
... return 'Instance Method'
...
>>> c.do = doo
>>> c.__str__ = strf
>>> print(c)
Class String
>>> print(c.do())
Instance Method

2. If an object's type has a __getattribute__ attribute, then this


method is invoked to get the attribute whether this attribute is
present or not. It is the total responsibility of __getattribute__ to
get the attribute. As shown in the following code snippet, even if
the do method is present, it is not found as getattribute didn't
return any attribute:
>>> class C:
... def do(self):
... print("asdf")
... def __getattribute__(self,attr):
... raise AttributeError('object
has no attribute "%s"'%attr)
...
>>> c = C()
>>> c.do()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in __getattribute__
AttributeError: object has no attribute "do"
>>>

3. Search in object's type __dict__ to find the attribute. If it is


present, and it is data descriptor, return it:
>>> class Desc:
... def __init__(self, i):
... self.i = i
... def __get__(self, obj, objtype):
... return self.i
... def __set__(self,obj, value):
... self.i = value
...
>>> class C:
... attx = Desc(23)
...
>>> c = C()
>>> c.attx
23
>>> c.__dict__['attx'] = 1234
>>> c.attx
23
>>> C.attx = 12
>>> c.attx
1234

4. Search in object's __dict__ type (and if this object is class,


search bases __dict__ as well) to find the attribute. If the
attribute is descriptor, return the result.
5. Search in object's type__dict__ to find the attribute. If the
attribute is found, return it. If it is non-data descriptor, return its
result, and check in other bases using the same logic:
>>> class Desc:
... def __init__(self, i):
... self.i = i
... def __get__(self, obj, objtype):
... return self.i
...
>>> class C:
... attx = Desc(23)
...
>>> c = C()
>>> c.attx
23
>>> c.__dict__['attx'] = 34
>>> c.attx
34

6. If object type's __getattr__ is defined, check whether it can give


us the attribute:
>>> class C:
... def __getattr__(self, key):
... return key+'_#'
...
>>> c = C()
>>> c.asdf
'asdf_#'

7. Raise AttributeError.

Descriptors
Key 9: Making custom behavior attributes.

Any attribute of a class, which is an object defining any of these


methods, acts as a descriptor:

__get__(self, obj, type=None) --> value


__set__(self, obj, value) --> None
__delete__(self, obj) --> None
When an attribute is searched in an object first, it is searched in its
dictionary then its type's (base class's) dictionary. If found, object has
one of these methods defined and that method is invoked instead.
Let's assume that b is an instance of the B class, then the following
will happen:

Invocation through class is type.__getattribute__()


transforming to B.__dict__['x'].__get__(None, B)
Invocation through instance is object .__getattribute__() -->
type(b).__dict__['x'].__get__(b, type(b))

Objects with only __get__ are non-data descriptors, and objects that
include __set__ / __del__ are data descriptors. Data descriptors take
precedence over instance attributes, whereas non-data descriptors
do not.

Class, static, and instance methods


Key 10: Implementing class method and static method.

Class, static, and instance methods are all implementable using


descriptors. We can understand descriptors and these methods in
one go:

Class methods are methods that always get class as their first
argument and they can be executed without any instance of
class.
Static methods are methods that do not get any implicit objects
as first argument when executed via class or instance.
Instance methods get instances when called via instance but no
implicit argument when called via class.

A sample code usage of these methods is as follows:

>>> class C:
... @staticmethod
... def sdo(*args):
... print(args)
... @classmethod
... def cdo(*args):
... print(args)
... def do(*args):
... print(args)
...
>>> ic = C()
# staticmethod called through class: no implicit
argument is passed
>>> C.sdo(1,2)
(1, 2)
# staticmethod called through instance:no implicit
argument is passed
>>> ic.sdo(1,2)(1, 2)
# classmethod called through instance: first
argument implicitly class
>>> ic.cdo(1,2)
(<class '__main__.C'>, 1, 2)
# classmethod called through class: first argument
implicitly class
>>> C.cdo(1,2)
(<class '__main__.C'>, 1, 2)
# instancemethod called through instance: first
argument implicitly instance
>>> ic.do(1,2)
(<__main__.C object at 0x00DC9E30>, 1, 2)
#instancemethod called through class: no implicit
argument, acts like static method.
>>> C.do(1,2)
(1, 2)

They can be understood and implemented using descriptors easily


as follows:

from functools import partial


>>> class my_instancemethod:
... def __init__(self, f):
... # we store reference to function in
instance
... # for future reference
... self.f = f
... def __get__(self, obj, objtype):
... # obj is None when called from class
... # objtype is always present
... if obj is not None:
... return partial(self.f,obj)
... else: # called from class
... return self.f
...
>>> class my_classmethod:
... def __init__(self, f):
... self.f = f
... def __get__(self, obj, objtype):
... # we pass objtype i.e class object
... # when called from instance or class
... return partial(self.f,objtype)
...
>>> class my_staticmethod:
... def __init__(self, f):
... self.f = f
... def __get__(self, obj, objtype):
... # we do not pass anything
... # for both conditions
... return self.f
...
>>> class C:
... @my_instancemethod
... def ido(*args):
... print("imethod",args)
... @my_classmethod
... def cdo(*args):
... print("cmethod",args)
... @my_staticmethod
... def sdo(*args):
... print("smethod",args)
...
>>> c = C()
>>> c.ido(1,2)
imethod (<__main__.C object at 0x00D7CBD0>, 1, 2)
>>> C.ido(1,2)
imethod (1, 2)
>>> c.cdo(1,2)
cmethod (<class '__main__.C'>, 1, 2)
>>> C.cdo(1,2)
cmethod (<class '__main__.C'>, 1, 2)
>>> c.sdo(1,2)
smethod (1, 2)
>>> C.sdo(1,2)
smethod (1, 2)

Tip
Downloading the example code

You can download the example code files from your account at
http://www.packtpub.com for all the Packt Publishing books you
have purchased. If you purchased this book elsewhere, you can
visit http://www.packtpub.com/support and register to have the
files e-mailed directly to you.
Summary
In this chapter, we dived into how objects work in the Python
language, how are they connected, and how are they called.
Descriptors and instance creation are very important topics as they
give us a picture of how system works. We also dived into how
attributes are looked up for objects.

Now, we are all prepared to learn how to use language constructs to


their maximum potential. In the next chapter, we will also discover
utilities that are extremely helpful in elegantly finishing a project.
Chapter 2. Namespaces and
Classes
In the previous chapter, we covered how objects worked. In this
chapter, we will explore how objects are made available to code via
reference, specifically how namespaces work, what modules are,
and how they are imported. We will also cover topics related to
classes, such as language protocols, MRO, and abstract classes.
We will discuss the following topics:

Namespaces
Imports and modules
Class multiple inheritance, MRO, super
Protocols
Abstract classes

How referencing objects work –


namespaces
Key 1: Interrelations between objects.

The scope is the visibility of a name within a code block. Namespace


is mapping from names to objects. Namespaces are important in
order to maintain localization and avoid name collision. Every
module has a global namespace. Modules store mapping from
variable name to objects in their __dict__ attribute, which is a normal
Python dictionary along with information to reload it, package
information, and so on.

Every module's global namespace has an implicit reference to the


built-in module; hence, objects that are in the built-in module are
always available. We can also import other modules in the main
script. When we use the syntax import module name, a mapping with
module name to module object is created in the global namespace of
the current module. For import statements with syntax such as
import modname as modrename, mapping is created with a new name
to module object.

We are always in the __main__ module's global namespace when the


program starts, as it is the module that imports all others. When we
import a variable from another module, only an entry is created for
that variable in the global namespace pointing at the referenced
object. Now interestingly, if this variable references a function object,
and if this function uses a global variable, then this variable will be
searched in the global namespace of the module that the function
was defined in, not in the module that we imported this function to.
This is possible because functions have the __globals__ attribute
that points to its __dict__ modules, or in short, its modules
namespace.

All modules that are loaded and referenced are cached in


sys.modules. All imported modules are names pointing to objects in
sys.modules. Let's define a new module like this with the name
new.py:

k = 10
def foo():
print(k)

By importing this module in the interactive session, we can see how


global namespaces work. When this module is reloaded, its
namespace dictionary is updated, not recreated. Hence, if you attach
anything new from the outside of the module to it, it will survive
reload:

>>> import importlib


>>> import new
>>> from new import foo
>>> import sys
>>> foo()
10
>>> new.foo()
10
>>> foo.__globals__ is sys.modules['new'].__dict__
# dictionary used by namespace and function
attribute __globals__ is indeed same
True
>>> foo.__globals__['k'] = 20 # changing global
namespace dictionary
>>> new.do #attribute is not defined in the
module
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'new' has no attribute 'do'
>>> foo.__globals__['do'] = 22 #we are attaching
attribute to module from outside the module
>>> new.do
22
>>> foo() # we get updated value for global
variable
20
>>> new.foo()
20
>>> importlib.reload(new) #reload repopulates old
modules dictionary
<module 'new' from '/tmp/new.py'>
>>> new.do #it didn't got updated as it was
populated from outside.
22
>>> new.foo() #variables updated by execution of
code in module are updated
10
>>>

If we use the functions that are defined in different modules to


compose a class on runtime, such as using metaclasses, or class
decorators, this can bring up surprises as each function could be
using a different global namespace.

Locals are simple and they work in the way that you expect. Each
function call gets its own copy of variables. Nonlocal variables make
variables that are defined in the outer scope (not global namespace)
accessible to the current code block. In the following code example,
we can see how variables can be referenced in enclosed functions.
Code blocks are able to reference variables that are defined in
enclosing scopes. Hence, if a variable is not defined in a function but
in an enclosing function, we are able to get its value. If, after
referencing a variable in an outer scope, we assign a value to this
variable in a code block, it will confuse the interpreter in finding the
right variable, and we will get the value from the current local scope.
If we assign a value to the variable, it defaults to the local variable.
We can specify that we want to work with an enclosing variable
using a nonlocal keyword:

>>> #variable in enclosing scope can be referenced


any level deep
...
>>> def f1():
... v1 = "ohm"
... def f2():
... print("f2",v1)
... def f3():
... print("f3",v1)
... f3()
... f2()
...
>>> f1()
f2 ohm
f3 ohm
>>>
>>> #variable can be made non-local (variable in
outer scopes) skipping one level of enclosing
scope
...
>>> def f1():
... v1 = "ohm"
... def f2():
... print("f2",v1)
... def f3():
... nonlocal v1
... v1 = "mho"
... print("f3",v1)
... f3()
... print("f2",v1)
... f2()
... print("f1",v1)
...
>>> f1()
Discovering Diverse Content Through
Random Scribd Documents
face if he had executed it.

The sergeant drew in a breath that raised the drum in a motion that spelt
rufflement. "Don't want you to tell me nothing but what you're asked," he
said. "Man lying here hurt. Case of assault—hur!" He moved the drum
slowly in the direction of Mr. Puddlebox and this time "hured" before he
spoke. "Hur! Thought I knew you as I come along. Seen you afore—in the
dock,—ain't I?"

"I've been in so many," said Mr. Puddlebox amicably, wiping his face
from which the sweat streamed, "that if I've omitted yours, you must put it
down to oversight, not unfriendliness."

"None o' that!" returned the sergeant. "No sauce. I know yer. Charged
with assault, both of yer, an' anything said used evidence against yer. Hur!
Who's this man down here?"

"Look and see if you know him," Mr. Wriford suggested. "I don't."

The drum was again advanced to the ditch, and the counterbalancing
operation again very carefully put into process. Mr. Wriford's eyes danced
with the wild idea that possessed him. To cap this tremendous hullabaloo in
which he had been in it! in it! in it! To fly the wildest flight of all! To
overturn, with a walloping kick, a policeman!

He drew near to Mr. Puddlebox and pulled his sleeve to attract his
attention.

"Why, that's George!" said the sergeant, midway in operation of his


counterbalancing machine. "That's old George Huggs—hur!"

"Can't be!" said Mr. Wriford and pulled Mr. Puddlebox's sleeve, and
pointed first at the tremendous uniformed stern gingerly lowering the tunic-
ed drum, then at his own foot, then down the road.

"Can't be!" returned the sergeant. "What yer mean, can't be! That's Miller
Derrybill's George Huggs. George! George, you've got to come out and
prosecute. George, I say—hur!"
Mr. Puddlebox, realizing the meaning of Mr. Wriford's pantomime,
puffed out his cheeks with laughter bursting to be free and nodded. Mr.
Wriford took one quick step and poised his foot at the tremendous target.

"George!" said the sergeant. "George Huggs! Hur!"

"Whoop!" said Mr. Wriford, and lashed.

The counterbalancing machine, not specified for this manner of usage,


overturned with the slow and awful movement of a somersaulting elephant.
One agonized scream from its owner, one dreadful bellow from George
Huggs as the enormous sergeant plunged head foremost upon him—Mr.
Wriford and Mr. Puddlebox, shouts of laughter handicapping their progress
but impossible of control, at full speed down the road.

CHAPTER IV

FIRST PERSON SINGULAR

Close of this day found the two in the outlying barn of a farm to which,
as night fell, Mr. Puddlebox had led the way. There had intervened between
it and the glorious battle-field an imperial midday banquet at an inn
provided by Mr. Wriford, who found sixteen shillings in his pocket and had
expended upon the meal four, upon sundries for further repasts one, and
upon a bottle of whisky to replace the music in Mr. Puddlebox's coat-tail
three and six. Thence a long amble to put much countryside between
themselves and the mighty gentlemen left in the ditch, and so luxuriously to
bed upon delicious hay, three parts of the whisky in the bottle, the other
quarter comfortably packed into Mr. Puddlebox.
Through the banquet and through the day there had been bursts of
laughter, started by one and immediately chorused by the other, at
recollections of the stupendous struggle and the stupendous kick; also,
prompted by Mr. Wriford, reiterated conversation upon a particular aspect
of the affair.

"I did my share?" Mr. Wriford would eagerly inquire.

"Loony, you did two men's share," Mr. Puddlebox would reply. "And
your kick of the policeman was another two men's—four men's share, boy. I
didn't want you in it, loony. You're not fit for such, I thought. But you
glumphed 'em, boy! You glumphed 'em like six men! Loony, you're
unspooking—you're unspooking double quick!"

Mr. Wriford thrilled at that and laughed aloud and swung his arms in
glee, and through the advancing night, lying warmly in the hay by Mr.
Puddlebox's side, continued to feast upon it and to chuckle over it; and
while he feasted and chuckled very often said to himself: "And that's the
way to get rid of myself following me. When I was frightened by the
wagon, he came. When I was walloping and smashing, he went and hasn't
come back. Very well. Now I know."

II

Mr. Wriford enjoyed some hours of dreamless sleep. He awoke, and on


the hay and in the darkness lay awake and thought.

"Well, this is a very funny state of affairs," Mr. Wriford thought. "Except
that I'm in a barn and shall get locked up for a tramp if I'm caught, or at
least into a devil of a row with the farmer if he catches me, I'm dashed if I
know where I am. I've stolen a ride on a wagon, and I've had a most
extraordinary fight in the road with the chap who was driving it. My eyes
were shut half the time. I wonder I wasn't killed. I must have got some
fearful smashes. I suppose I didn't feel them—you don't when your blood's
up. I belted him a few stiff 'uns, though; by gad, I did! I don't know how I
had the pluck. I wonder what's the matter with me—I mean to say, me!
fighting a chap like that. And then I kicked a policeman. Good Lord, you
know—that's about the most appalling thing a man can do! Kicked him
bang over—heels over head! By gad, he did go a buster, though!" And at
recollection of the buster that the police sergeant went, Mr. Wriford began
to laugh and laughed quietly for a good while.

Then he began to think again. "I chucked myself into the river," Mr.
Wriford thought. "I'd forgotten that. I've not thought about it since I did it.
Good Lord, that was a thing to do! I didn't mean to. One moment I was
walking along the Embankment, and the next I was falling in. I wonder
what I did in between—how I got up, how I got in. I wanted to die. Yes, I
tried to drown and die. I suppose I'm not dead? No, I can't possibly be dead.
Everything's funny enough to be another world, but I take my oath I'm not
dead. This chap Puddlebox—which can't possibly be his real name—thinks
I'm mad. But I'm absolutely not mad. I may be dead—I know I'm not,
though; at least I'm pretty sure I'm not—but I'm dashed if I'm mad. I've been
too near madness—God knows—not to know it when I see it. Those sort of
rushes-up in my head—I might have gone mad any time with one of those.
Well, they're gone. I'll never have another; I feel absolutely sure of that. My
head feels empty—feels as though it was a different part of me, like I've
known my foot feel when it's gone to sleep and I can touch it without
feeling it. Before, my head used to feel full, cram full. That's the only
difference and that's not mad: it's just the reverse, if anything. What about
seeing myself? Who am I then? I mean to say, am I the one I can see or the
one I think I am? Well, the thing is, is there any one there when I see him or
is it only imagination, only a delusion? If it's a delusion, then it's madness
and I'm mad. Well, the very fact that I know that, proves it isn't a delusion
and proves I'm absolutely sane; the very fact that I can lie here and argue
about it and that I can't see it now because it isn't here, and can see it
sometimes because it is there—that very fact proves I'm not mad. I think I
know what it is. It's the same sort of thing as I remember once or twice
years ago, when I first came to London and had a night out with some men
and got a bit tipsy. I remember then sort of seeing myself—sort of trying to
pull myself together and realise who I really was; and while I was trying, I
could see myself playing the fool and staggering about and making an ass
of myself. It was the drink that did that—that kind of separated me into two.
Now I've done the same thing by trying to drown myself and nearly
succeeding and by coming into this extraordinary state of affairs after living
in a groove so long. Part of me is still in that old life and gets the upper
hand of me sometimes, just as the drink used to. I've only got to realise that
I've done with all that, and I've only got to smash about and not care what
happens to me, and I'm all right.

"And I have done with it," cried Mr. Wriford aloud and fiercely, and
sitting up and continuing to speak very quickly. "I have done with it! All
these years I've been shut up and never enjoyed myself like other men. I've
given up my life to others and got mixed up in their troubles and never been
able to live for myself. Now I'm going to begin life all over again. I'm not
going to care for anybody. I'm just going to let myself—go! I'm not going to
care what happens. I'm not going to think of other people's feelings. I'm not
going to be polite or care a damn what anybody thinks. If I get hurt, I'm just
going to be hurt and not care. If I want to do what would have seemed
wrong in the old days, I'm just going to do it and not care. I've cared too
much! that's what's been wrong with me. Now I'm not going to care for
anything or anybody. This chap Puddlebox said that what was wrong with
me was that I thought too much about myself. I remember Brida telling me
the same thing once. That's just exactly what it's not. All my life I've
thought too much about other people. That's been the trouble. Done!
Whoop, my boy, it's done! There's not going to be anybody in the world for
myself except me—yes, and not even me. I'm going to be outside it all and
just look on—and this me lying here can do what it likes, anything it likes.
Hurt itself, starve itself, chuck itself down—that's one of the things I want
to do: to get up somewhere and chuck myself down smash! and see what
happens and laugh at it, whatever it is. I'm simply not going to care. I
belong to myself—or rather myself belongs to me, and I'm going to do what
I like with it—just exactly what I like. Puddlebox!"

Mr. Wriford turned to the recumbent form beside him to nudge it into
wakefulness, but found it already awake. The gleam of Mr. Puddlebox's
open eyes was to be seen in the darkness, and Mr. Puddlebox said: "Loony,
how many of you are here this morning?"
"There's only me," said Mr. Wriford. "I'm not going to care—"

"You're spooked again, loony," Mr. Puddlebox interrupted him. "I've


been listening to you talking."

"Well, you can listen to this," said Mr. Wriford. "I'm not going to care a
damn what happens to me or care a hang for anybody—you or anybody."

"Very well," said Mr. Puddlebox. "That's settled."

"So it is," said Mr. Wriford, "and I tell you what I'm going to do first."

Sufficient of morning was by now stealing through cracks and crevices


of the barn to radiate its gloom. Two great doors admitted to the interior.
Between them ran a gangway of bricked floor with hay stacked upwards to
the roof on either hand. Mr. Wriford could almost touch the roof where now
he stood up, his feet sinking in the hay, and could see the top of the ladder
by which overnight they had climbed to their bed. "What I'm going to do
first," said Mr. Wriford, pointing to the gangway beneath them, "is to jump
down there and see what happens."

"Well, I'll tell you what you are going to do last," returned Mr.
Puddlebox, "and that also is jump down there, because you'll break your
neck and that'll be the end of you, boy."

"I'm going to see," said Mr. Wriford. "Smash! That's just what I want to
see."

"Half a minute," said Mr. Puddlebox and caught Mr. Wriford's coat. "Just
a moment, my loony, for there's some one else wants to see also. There's
some one coming in."
CHAPTER V

INTENTIONS, IN HIS NIGHTSHIRT, OF A


FARMER

It was symptomatic of Mr. Wriford's state in these days that any


interruption at once diverted him from his immediate purpose and turned
him eagerly to whatever new excitement offered. So now, and here was an
excitement that promised richly. Perched up there in the darkness and with
the guilty knowledge of being a trespasser, it was a very tingling thing to
hear the sounds to which Mr. Puddlebox had called attention and, peering
towards the door from which they came, to speculate into what alarms they
should develop. This was speedily discovered. The sounds proceeded from
the door opposite to that by which entry had been made overnight, and from
fumbling passed into a jingling of keys, a turning of the lock, and so gave
admittance to a gleam of yellow light that immediately was followed by a
man bearing a lantern swinging from his left hand and in his right a bunch
of keys.

This was a curious gentleman who now performed curious actions. First
he peered about him, holding the lantern aloft, and this disclosed him to be
short and very ugly, having beneath a black growth on his upper lip yellow
teeth that protruded and came down upon his lower. This gentleman was
hatless and in a shirt without collar lumped so bulgingly into the top of his
trousers as to present the idea that it was very long. Indeed, as he turned
about, the lantern at arm's length above his head, it became clear to those
who watched that this was his nightshirt that he wore. Next he set down the
lantern, locked the door by which he had entered, placed across it an iron
bar which fell into a bracket on either side, took up his light again, and
proceeded along the gangway.

All this he did very stealthily—turning the key so that the lock could
scarcely be heard as it responded, fitting his iron bar, first with great
attention on the one side and then on the other, and then walking forward on
his toes with manifest straining after secrecy. A rat scurried in the straw
behind him, and he twisted round towards it as though terribly startled, with
a quick hiss of his breath and with his hand that held the keys clapped
swiftly to his heart.

Now he came beneath the stack upon which our two trespassers watched
and wondered, and there remained for a space lost from view. There was to
be heard a clinking as though he operated with his lantern, and with it a
shuffling as though he disturbed the straw. Next he suddenly went very
swiftly to the further door, passed through it in haste, and could be heard
locking it from the outside, then wrenching at the key as though in a great
hurry to be gone, then gone.

"That's funny," said Mr. Wriford. "Was he looking for something?"

"He was precious secret about it," said Mr. Puddlebox.

"Damn it," cried Mr. Wriford, "he's left his lamp behind. You can see the
gleam."

Mr. Puddlebox, like curious hound that investigates the breeze, sat with
chin up and with twitching nose; then sprang to his feet. "Curse it," cried
Mr. Puddlebox, "he's set the place afire! Skip, loony, skip, or we're
trapped!" and Mr. Puddlebox hurled himself towards the ladder, reversed
himself upon it, missed a rung in his haste, and with a very loud cry
disappeared with great swiftness, and with a very loud bump crashed with
great force to the ground.

Mr. Wriford followed. Mr. Wriford, with no very clear comprehension of


what was toward, but very eager, also slipped, also slithered, and also
crashed.

"Hell!" cried Mr. Puddlebox. "Blink! Get off me, loony!"

Mr. Wriford was raised and rolled as by convulsion of a mountain


beneath him. As he rolled, he had a glimpse of the lantern embedded in a
nest of straw, its smoky flame naked of chimney, and from the flame
towards the straw a strip of cloth with a little red smoulder midway upon it.
As he sat up, the smoulder flared to a little puff of flame, ran swiftly down
the cloth, flared again in the straw, then was eclipsed beneath the mighty
Puddlebox, bounded forward from hands and knees upon it.

"The lamp, boy!" bellowed Mr. Puddlebox.

Mr. Wriford dashed at the lamp, bestowed upon it all the breath he could
summon, and flattened himself beside Mr. Puddlebox upon a spread of
flame that, as he blew, ran from lantern to straw.

"Good boy!" said Mr. Puddlebox. "That was quick," and himself at once
did something quicker. Very cautiously first he raised his body upon his
hands and knees, squinted beneath it, then dropped it again with immense
swiftness and wriggled it violently into the straw. "I'm still burning down
here," cried Mr. Puddlebox, and turned a face of much woe and concern
towards Mr. Wriford, and inquired: "How's yours, loony?"

Mr. Wriford went through the first, or cautious, portion of Mr.


Puddlebox's performance and announced: "Mine's out. Get up and let's have
a look."

"Why," said Mr. Puddlebox irritably, "how to the devil can I get up? If I
get up it will burst out, and if I lie here I shall be slowly roasted alive. This
is the most devil of a predicament that ever a man was in, and I will
challenge any man to be in a worse. Unch—my stomach is already like a
pot on the fire. Ooch! Blink."

"Well, the fire's simply gaining while you lie there," cried Mr. Wriford.
"I can smell it. It's simply gaining, you ass."

"Ass!" cried Mr. Puddlebox. "Ass! I tell you it is you will look an ass
and a roast ass if I move. I can get no weight on it to crush it like this.
Unch! What I am going to do is to turn over and press it down, moreover I
can bear roasting better on that other side of me. Now be ready to give me a
hand if the flames burst, and be ready to run, loony—up the ladder and try
the roof."

Mr. Puddlebox then raised his chest upon his arms, made a face of great
agony as the released pressure caused his stomach to feel the heat more
fiercely, then with a stupendous convulsion hurled himself about and gave
first a very loud cry as the new quarter of his person took the fire and then
many wriggles and a succession of groans as with great courage he pressed
his seat down upon the smouldering embers. Lower he wriggled, still
groaning. "Ah," groaned Mr. Puddlebox. "Arp. Ooop. Erp. Blink. Eep. Erps.
Ooop. Hell!" He then felt about him with his hands, and with the fingers of
one finding what he sought and finding it uncommonly hot, brought his
fingers to his mouth with a bitter yelp; fumbled again most cautiously,
wriggled yet more determinedly, groaned anew, yet at longer intervals, and
presently, a beaming smile overspreading his countenance, raised an arm
aloft and announced triumphantly: "Out!"

"Out!" repeated Mr. Puddlebox, rising and beating smoulder from his
waistcoat with one hand and from his trousers with the other.

"You were devilish plucky," said Mr. Wriford. "I can't help laughing now
it's over, you know. But it was a narrow squeak. You were quick getting
down, and you saved both our lives by hanging on like that."

"Why, you were quick, too, boy," said Mr. Puddlebox. "You were quick
after me as a flash—and plucky. I'd not have done it alone. You're coming
on, boy; you're coming on. You're unspooking every minute."

"I did nothing," said Mr. Wriford. But he was secretly glad at the praise,
and this, joined to his earlier determination to care nothing for anybody nor
for what happened to him, spurred him to give eager aid to what Mr.
Puddlebox now proposed.

"I am parboiled in front," said Mr. Puddlebox, finishing his beating of


himself, "and I am underdone behind; but the fire is out, and now it is for us
to get out. Loony, that was a damned, cold-blooded villain that came here to
burn us, and a damned ugly villain as ever I saw, and I will challenge any
man to show me an uglier. There is a lesson to be taught him, my loony, and
there is compensation to be paid by him; and this he shall be taught and
shall pay before I am an hour older in sin."

With this Mr. Puddlebox marched very determinedly up the ladder which
he had descended very abruptly, and preceded Mr. Wriford across the top of
the hay to the point where this was nearest met by the sloping roof. "It's all
very fine," doubted Mr. Wriford, addressing the determined back as they
made their way, "it's all very fine, Puddlebox, but mind you we look like
getting ourselves in a devil of a fix if we go messing round this chap,
whoever he is. He's probably the farmer. If he is it looks as if he wanted to
fire his barn to get the insurance; and it'll be an easy thing for him, and a
jolly good thing, to shove the blame on us. That's what I think."

"Loony," returned Mr. Puddlebox, arrived under the roof and facing him,
"you think too much, and that's just what's the matter with you, as I've told
you before. To begin with, his barn has not been burnt, and that's just where
we've got him. We are heroes, my loony, and I am a burnt hero, and some
one's got to pay for it."

Mr. Wriford's reply to this was first a look of sharp despair upon his face
and then to raise his fists and drum them fiercely upon his head.

"Why, boy! boy!" cried Mr. Puddlebox and caught Mr. Wriford's hands
and held them. "Why, what to the devil is that for?"

"That's for what I was doing!" cried Mr. Wriford. "That's because I
stopped to think. I'm never going to think any more, and I'm never going to
stop any more. And if I catch myself stopping or thinking I shall kill myself
if need be!"

"Well, why to the devil," said Mr. Puddlebox very quickly, "do you stop
to beat yourself instead of doing what I tell you? Where there's a little hole,
my loony, there's easy work to make a big one. Here's plenty of little holes
in these old tiles of this roof. Up on my shoulders, loony, and get to work on
them."

CHAPTER VI
RISE AND FALL OF INTEREST IN A FARMER

Symptomatic again of Mr. Wriford's condition that his storm was gone as
quickly as it came. Now filled him only the adventure of breaking out; and
he was no sooner, with much laughter, straddled upon Mr. Puddlebox's
shoulders and pulling at the tiles, than with smallest effort the little holes in
the weather-worn roofing became the large one that Mr. Puddlebox had
promised.

"Whoa!" cried Mr. Puddlebox, plunging in the yielding hay beneath Mr.
Wriford's weight.

"Whoa!" echoed Mr. Wriford, and to check the staggering grabbed at the
crumbling tiles.

"Blink!" cried Mr. Puddlebox and collapsed. "Curse me, is the roof come
in on us?"

Mr. Wriford extricated himself and stood away, rubbing his head that had
received tiles like discharge of thunderbolts. "A pretty good chunk of it
has," said Mr. Wriford. "There's your hole right enough."

This was indeed a great rent capable of accommodating their purpose


and more; and Mr. Puddlebox, whose head also needed rubbing, now arose
and examined it with his customary cheerfulness. "That's a fine hole, boy,"
said Mr. Puddlebox, "and a clever one also, for here to this side of it runs a
beam which, if it will support us, will have us out, and if it will not, will
fetch the whole roof down and have us out that way. Jump for the beam,
boy, while I lift you."

Mr. Puddlebox's hands on either side of Mr. Wriford's hips, jumping him,
and then at his legs, shoving him, enabled Mr. Wriford with small exertion
soon to be straddled along the roof, and then with very enormous exertion
to engage in the prodigious task of dragging Mr. Puddlebox after him.
When this was accomplished so far as that Mr. Puddlebox's arms, head and
chest were upon the beam and the remainder of his body suspended from it,
"It's devilish steep up here," grunted Mr. Wriford, flat on his face, hauling
amain on the slack of Mr. Puddlebox's trousers, and not at all at his
strongest by reason of much laughter at Mr. Puddlebox's groans and
strainings; "it's devilish steep and nothing to hold on to. Look out how you
come or you'll have us both over and break our necks."

"Well, when to the devil shall I come?" groaned Mr. Puddlebox. "This is
the very devil of a pain to have my stomach in; and I challenge any man to
have his stomach in a worse. I must drop down again or I am like to be cut
in halves."

"I'll never get you up again if you do," Mr. Wriford told him. "I've got
your trousers tight to heave you if you'll swing. Swing your legs sideways,
and when I say 'Three' swing them up on the beam as high as you can."

The counting of One and Two set Mr. Puddlebox's legs, aided by Mr.
Wriford's hands on his stern, swinging like a vast pendulum. "Hard as you
can as you come back," called Mr. Wriford, "and hang on like death when
you're up—THREE!"

With a most tremendous swing the boots of the pendulum reached the
roof and clawed a foothold. Between heels and one shoulder its powerful
stern depended ponderously above the hay. "Heave yourself!" shouted Mr.
Wriford, hauling on the trousers. "Roll yourself! Heave yourself!" Mr.
Puddlebox heaved enormously, rolled tremendously, and, like the
counterbalancing machine of the police sergeant, up came his stern, and
prodigiously over.

"Look out!" cried Mr. Wriford. "Look out! Let go, you ass!"

"Blink!" cried Mr. Puddlebox, flat and rolling on the steep pitch of the
roof. "Blink! We're killed!" clutched anew at Mr. Wriford, tore him from his
moorings, and, knotted with him in panic-stricken embrace, whirled away
to take the plunge and then the drop.

The strawyard in which the barn stood was fortunately well bedded in
straw about the walls of the building. When, with tremendous thump, with
the familiar sound of smashing glass and familiar scent of whisky upon the
morning air, the two had come to rest and had discovered themselves
unbroken—"Why the dickens didn't you let go of me?" Mr. Wriford
demanded. "I could have hung on with one hand and held you."

Mr. Puddlebox sat up with his jolly smile and glancing at the height of
their descent gave with much fervour:

"O ye falls of the Lord, bless ye the Lord; praise Him and magnify Him
for ever!"

Mr. Wriford jumped up and waved his arms and laughed aloud and then
cried: "That was all right. Now I'm not caring! Now I'm living!"

"Why, look you, my loony," said Mr. Puddlebox, beaming upon him with
immense delight, "look you, that was very much all right; and that is why I
return praise for it. We might have been killed in falling from there, but
most certainly we are not killed; and if we had not fallen we should still be
up there, and how I should have found heart to make such a devil of a leap I
am not at all aware. Here we are down and nothing the worse save for this
disaster that, curse me, my whisky is gone again. Thus there is cause for
praise in everything, as I have told you, and in this fall such mighty good
cause as I shall challenge you or any man to look at that roof and deny.
Now," continued Mr. Puddlebox, getting to his feet, "do you beat your head
again, boy, or do we proceed to the farmhouse?"

Mr. Wriford said seriously, "No, I'm damned if I beat my head now,
because that time I didn't stop and didn't think except just for a second when
we were falling, and then I couldn't stop even if I'd wanted to. No, I'm
damned if I beat my head this time."

"What it is," said Mr. Puddlebox, emptying his tail-pocket of the broken
whisky bottle, and proceeding with Mr. Wriford towards the farmhouse,
"what it is, is that you are damned if you do beat your head—that is, you are
spooked, loony, which is the same thing."

Mr. Wriford paid no apparent attention to this, but his glee at believing
that, as he had said, he now was not caring and now was living, gave an
excited fierceness to his share in their immediate behaviour, which now
became very extraordinary.
CHAPTER VII

PROFOUND ATTACHMENT TO HIS FARM OF A


FARMER

The front door of the farmhouse, embowered in a porch, was found to be


on the side further from the strawyard. A fine knocker, very massive, hung
upon the door, and this Mr. Puddlebox now seized and operated very loudly,
with effect of noise which, echoing through the silent house and through the
still air of early morning, would in former circumstances have utterly
horrified Mr. Wriford and have put him to panic-stricken flight in very
natural apprehension of what it would bring forth. Now, however, it had no
other effect upon him than first to make him give a nervous gasp and
nervous laugh of nervous glee, and next himself to seize the knocker and
put into it all the determination of those old days forever ended and these
new days of freedom in which he cared for nothing and for nobody now
begun.

Fiercely Mr. Wriford knocked until his arm was tired and then flung
down the knocker with a last crash and turned on Mr. Puddlebox a flushed
face and eyes that gleamed. "I don't care a damn what happens!" he cried.

"My word," said Mr. Puddlebox, gazing at him, "something is like to


happen now after all that din. You've got hold of yourself this time, boy."

Mr. Wriford laughed recklessly. "I'll show you," he cried, "I'll show you
this time!" and took up the knocker again.

But something was shown without his further effort. His hand was
scarcely put to the knocker, when a casement window grated above the
porch in which they stood, and a very harsh voice cried: "What's up? Who's
that? What's the matter there?" and then with a change of tone: "What's that
light in the sky? Is there a fire?"

Mr. Wriford, his new fierceness of not caring, of letting himself go,
fierce upon him, was for rushing out of the porch to look up at the window
and face this inquiry, but Mr. Puddlebox a moment restrained him. "That's
our old villain for sure," Mr. Puddlebox whispered. "There's no ghost of
light in the sky that fire would make; but he's prepared for one, and that
proves him the old villain that he is."

"Now, then!" rasped the voice. "Who are you down there? What's up?
What's that light in the sky?"

Out from the porch charged Mr. Wriford, Mr. Puddlebox with a hand on
his arm bidding him: "Go warily, boy; leave this to me."

So they faced the window, and there, sure enough, framed within it, was
displayed the gentleman that had been seen with the lantern, with the black
scrub upon his upper lip, and with the yellow teeth protruded beneath it.

"That light is the moon," Mr. Puddlebox informed him pleasantly. "Luna,
the dear old moon. Queen-Empress of the skies."

"The moon!" shouted the yellow-toothed gentleman. "The moon! Who


the devil are you, and what's your business?"

Mr. Puddlebox responded stoutly to this rough address. "Why, what to


the devil else should it be but the moon? Is it something else you're looking
for—?"

The yellow-toothed gentleman interrupted him by leaning out to his


waist from the window and bellowing: "Something else! Come, what the
devil's up and what's your business, or I'll rouse the house and set about the
pair of 'ee."

Then Mr. Wriford, no longer to be restrained. Mr. Wriford, fierce to


indulge his resolution not to care for anybody and shaking with the
excitement of it. Mr. Wriford, to Mr. Puddlebox's much astonishment, in
huge and ferocious bawl: "What's up!" bawled Mr. Wriford, hopping about
in reckless ecstasy of fierceness. "What's up! Why, you know jolly well
what's up, you beastly old villain. Tried to set your barn afire, you ugly-
faced old scoundrel! I saw you! I was in there! I saw you with your lamp!
Come down, you rotten-toothed old fiend! Come down and have your face
smashed, you miserable old sinner!"

The gentleman thus opprobriously addressed disappeared with great


swiftness, and immediately could be heard thumping down-stairs with
sounds that betokened bare feet.

"That's done it," said Mr. Wriford, wiping his face which was very hot,
and placed himself before the porch to await the expected arrival.

"My goodness, it has," said Mr. Puddlebox. "You've let yourself go this
time, boy. And what the devil is going to happen next—

"I'll show you," cried Mr. Wriford and, as the key turned in the lock and
the door opened, proceeded to the demonstration thus promised with a
fierceness of action even more astonishing than his earlier outburst of
words.

The door was no sooner opened to reveal the yellow-toothed gentleman


in his nightshirt and bare feet, than Mr. Wriford rushed upon him, seized
him by his flowing garment, and dragged him forth into the yard. Mr.
Wriford then revolved very swiftly, causing the yellow-toothed gentleman,
who had the wider ambit to perform, to revolve more swiftly yet, and this
on naked feet that made him complain very loudly and bound very highly
when they lighted upon a stone, spun him in these dizzy circles down the
yard, and after a final maze at final speed released him with the result that
the yellow-toothed gentleman first performed a giddy whirl entirely on his
own account, then the half of another on his heels and in mortal danger of
overbalancing, and then, with the best intentions in the world to complete
this circuit, was checked by waltzing into his duck-pond, wherein with a
very loud shriek he disappeared.
Mr. Wriford again wiped his face, which was now much hotter than
before, and with a cry of "Come on!" to Mr. Puddlebox, who was staring in
amazement towards the pond and its struggling occupant, made a run to the
house. Mr. Puddlebox joined him within the door, and Mr. Wriford then
locked the door behind them, and looking very elatedly at Mr. Puddlebox,
inquired of him triumphantly: "Well, what about that?"

"Loony," said Mr. Puddlebox, "I never saw the like of it. It's a licker."

"So it is!" cried Mr. Wriford. "I fairly buzzed him, didn't I? You needn't
whisper. There's no one here but ourselves, I'm pretty sure. I'm pretty sure
that chap's managed to get the place to himself so that he could make no
mistake about getting his barn burnt down. Anyway, I'm going to see, and I
don't care a dash if there is." And by way of seeing, Mr. Wriford put up his
head and shouted: "Hulloa! Hulloa, is there anybody in here?"

"Hulloa!" echoed Mr. Puddlebox, subscribing with great glee to Mr.


Wriford's excitement.

"Hulloa!" cried Mr. Wriford in a very loud voice. "If anybody wants a hit
in the eye come along down and ask for it!"

To this engaging invitation there was from within the house no answer;
but from without, against the door, a very loud thud which was the yellow-
toothed gentleman hurling himself against it, and then his fists beating
against it and his voice crying: "Let me in! Let me in, won't you!"

"No, I won't!" called Mr. Wriford, and answered the banging with lusty
and defiant kicks. "Get back to your pond or I'll come and throw you there."

"I'm cold," cried the yellow-toothed gentleman, changing his voice to


one of entreaty. "Look here, I want to talk to you."

"Go and light your barn again and warm yourself," shouted Mr.
Puddlebox; but the laughter with which he shouted it was suddenly
checked, for the yellow-toothed gentleman was heard to call: "Hullo! Hi!
Jo! Quick, Jo! Come along quick!"
"Boy," said Mr. Puddlebox, "we ought to have got away from this while
he was in the pond. What to the devil's going to happen now?"

"Listen," said Mr. Wriford; but they had scarcely listened a minute
before there happened a sound of breaking glass in an adjoining room.
"They're getting in through a window," cried Mr. Wriford. "We must keep
them out."

Several doors led from the spacious old hall in which they stood, and Mr.
Puddlebox, choosing one, chose the wrong one, for here was an apartment
whose window stood intact and beyond which the sounds of entry could
still be heard. A further door in this room that might have led to them was
found to be locked and without key. Mr. Puddlebox and Mr. Wriford
charged back to the hall, down the hall alongside this room, through a door
which led to a passage behind it, and thence through another door which
revealed one gentleman in his nightshirt, yellow and black with mire from
head to foot, who was reaching down a wide-mouthed gun from the wall,
and another gentleman in corduroys, having a bucolic countenance which
was very white, who in the act of entry had one leg on the floor and the
other through the window.

II

"If they've got in we'll run for it," Mr. Puddlebox had said as they came
down the passage. But the room was entered so impetuously that the only
running done was, perforce, into it, and at that with a stumbling rush on the
part of Mr. Puddlebox into the back of the nightshirt and the collapse of Mr.
Wriford over Mr. Puddlebox's heels upon him. Mr. Puddlebox encircled the
nightshirt about its waist with his arms; the nightshirt, gun in hand,
staggered towards the corduroy and with the gun swept its supporting leg
from under it; the gun discharged itself through its bell-shaped mouth with
an appalling explosion; the corduroy with a loud shriek to the effect that he
was dead fell upon the head of the nightshirt; and there was immediately a
tumult of four bodies with sixteen whirling legs and arms, no party to which
had any clear perception as to the limbs that belonged to himself, or any
other strategy of campaign than to claw and thump at whatever portion of
whoever's body offered itself for the process. There were, with all this, cries
of very many kinds and much obscenity of meaning, changing thrice to a
universal bellow of horror as first a table and its contents discharged itself
upon the mass, then a dresser with an artillery of plates and dishes, and
finally a grandfather clock which, descending sideways along the wall,
swept with it a comprehensive array of mural decorations.

Assortment of arms and legs was at length begun out of all this welter by
the corduroyed gentleman who, finding himself not dead as he had
believed, but in great danger of reaching that state in some very horrible
form, found also his own hands and knees and upon them crawled away
very rapidly towards an adjoining room whose door stood invitingly open.
There were fastened to his legs as he did so a pair of hands whose owner he
first drew after him, then dislodged by, on the threshold of the open door,
beating at them with a broken plate, and having done so, sprung upright to
make for safety. The owner of the hands however sprung with him, attached
them—and it was Mr. Wriford—to his throat, and thrust him backwards into
the adjoining room and into the midst of several shallow pans of milk with
which the floor of this room was set.

This apartment was, in fact, the dairy; and here, while thunder and
crashing proceeded from the other room in which Mr. Puddlebox and the
nightshirt weltered, extraordinary contortions to the tune of great splashing
and tin-pan crashing were forced upon the corduroyed gentleman by Mr.
Wriford's hands at his throat. Broad shelves encircled this room, and first
the corduroyed gentleman was bent backwards over the lowest of these
until the back of his head adhered to some pounds of butter, then whirled
about and bent sideways until in some peril of meeting his end by
suffocation in cream, then inclined to the other side until a basket of eggs
were no longer at their highest market value, and finally hurled from Mr.
Wriford to go full length and with a large white splash into what pans of
milk remained in position on the floor.

Mr. Wriford, with a loud "Ha!" of triumph, and feeling, though greatly
bruised in the first portion of the fight and much besmeared with dairy-
produce in the second, much more of a man than he had ever felt before,
then dashed through the door and locked it upon the corduroy's struggles to
free himself from death in a milky grave, and then prepared to give fierce
assistance to the drier but as deadly fray still waging between Mr.
Puddlebox and the nightshirt.

Upon the welter of crockery and other debris here to view, these
combatants appeared to be practising for a combined rolling match, or to be
engaged in rolling the litter into a smooth and equable surface. Locked very
closely together by their arms, and with equal intensity by their legs, they
rolled first to one end of the room or to a piece of overturned furniture and
then, as if by common consent, back again to the other end or to another
obstacle. This they performed with immense swiftness and with no vocal
sounds save very distressed breathing as they rolled and very loud and
simultaneous Ur! as they checked at the end of a roll and started back for
the next.

As Mr. Wriford watched, himself breathing immensely after his own


exertions yet laughing excitedly at what he saw, he was given opportunity
of taking part by the rollers introducing a new diversion into their exercise.
This was provided by the grandfather clock, which, embedded in the debris
like a partly submerged coffin, now obstructed their progress. A common
spirit of splendid determination not to be stopped by it appeared
simultaneously to animate them. With one very loud Ur! they came against
it; with a secondhand a third and each time a louder Ur! charged it again
and again; with a fourth Ur! magnificently mounted it; and with a fifth, the
debris on this side being lower, plunged down from it. The shock in some
degree relaxed their embrace one with the other. From their locked forms a
pair of naked legs upshot. Mr. Wriford jumped for the ankles, clutched them
amain, and with the information "I've got his legs!" and with its effect,
encouraged Mr. Puddlebox to a mighty effort, whereby at length he broke
free from the other's grasp, sat upright upon the nightshirt's chest, and then,
securing its arms, faced about towards Mr. Wriford, and seated himself
upon the nightshirt's forehead.

"Where's yours?" said Mr. Puddlebox, when he had collected sufficient


breath for the question.
"Locked up in there," said Mr. Wriford, nodding his head towards the
dairy.

"Loony," said Mr. Puddlebox, "this has been the most devil of a thing
that ever any man has been in, and I challenge you or any man ever to have
been in a worse."

"I'll have you in a worse," bawled the nightshirt. "I'll—" and as though
incapable of giving sufficient words to his intentions he opened his mouth
very widely and emitted from it a long and roaring bellow. Into this cavern
of his jaws Mr. Puddlebox, now kneeling on the nightshirt's arms, dropped a
cloth cap very conveniently abandoned by the corduroy; and then, facing
across the prostrate form, Mr. Puddlebox and Mr. Wriford went into a
hysteria of laughter only checked at last by the nightshirt, successfully
advantaging himself of the weakening effect of their mirth, making a
tremendous struggle to overthrow them.

"But, loony," said Mr. Puddlebox when the farmer was again mastered,
"we are best out of this, for such a battle I could by no means fight again."

"Well, I don't care," said Mr. Wriford. "I don't care a dash what happens
or who comes. Still, we'd better go. First we must tie this chap up and then
clean ourselves. My man's all right in there. There's no window where he is
—only a grating round the top. I'll find something to fix this one with if you
can hold his legs."

This Mr. Puddlebox, by kneeling upon the nightshirt's arms and


stretching over them to his legs, was able to do, and Mr. Wriford, voyaging
the dishevelled room, gave presently a gleeful laugh and presented himself
before Mr. Puddlebox with a wooden box and with information that made
Mr. Puddlebox laugh also and the nightshirt, unable to shout, to express his
personal view in new and tremendous struggles.

"Nails," said Mr. Wriford, "and a hammer. We'll nail him down;" and
very methodically, working along each side of each extended arm, and
down each border of the nightshirt pulled taut across his person, proceeded
to attach the yellow-toothed gentleman to the floor more literally and more
closely than any occupier, unless similarly fastened, can ever have been
attached to his boyhood's home.

"There!" said Mr. Wriford, stepping back and regarding his handiwork,
which was indeed very creditably performed, with conscionable
satisfaction. "There you are, my boy, as tight as a sardine lid, and if you
utter a sound you'll get one through your head as well."

This, however, was a contingency which the nightshirt, thanks to the cap
in his mouth, was in no great danger of arousing, and leaving him to enjoy
the flavour of his gag and his unique metallic bordering, which from the
hue of his countenance and the flame of his eyes he appeared indisposed to
do, there now followed on the part of Mr. Wriford and Mr. Puddlebox a
very welcome and a highly necessary adjustment of their toilets. It was
performed by Mr. Puddlebox with his mouth prodigiously distended with a
meal collected from the kitchen, and by Mr. Wriford, as he cooled, with
astonished reflection upon the extraordinary escapades which he had now
added to his exploits of the previous day. "Well, this is a most extraordinary
state of affairs for me," reflected Mr. Wriford, much as he had reflected
earlier in the morning. "Most extraordinary, I'm dashed if it isn't! I've pretty
well killed a chap and drowned him in milk; and I've slung a chap into a
pond and then nailed him down by his nightshirt. Well, I'm doing things at
last; and I don't care a dash what happens; and I don't care a dash what
comes next."

III

Now this cogitation took place in an upper room whither Mr. Wriford
had repaired in quest of soap and brushes, and what came next came at once
and came very quickly, being first reported by Mr. Puddlebox, who at this
point rushed up-stairs to announce as rapidly as his distended mouth would
permit: "Loony, there's a cart come up to the door with four men in it—
hulkers!" and next illustrated by a loud knocking responsive to which there
immediately arose from the imprisoned corduroy a great shouting and from
the gagged and nailed-down nightshirt a muffled blaring as of a cow
restrained from its calf.

Very much quicker than might be supposed, and while Mr. Puddlebox
and Mr. Wriford stared one upon the other in irresolute concern, these
sounds blended into an enormous hullabaloo below stairs which spoke of
the entry by the window of the new arrivals, of the release from his gag of
the nailed-down nightshirt and from his milky gaol of the imprisoned
corduroy, and finally of wild and threatening search which now came
pouring very alarmingly up the stairs.

Mr. Wriford locked the door, Mr. Puddlebox opened the window, and
immediately their door was first rattled with cries of "Here they are!" and
then assailed by propulsion against it of very violent bodies.

The drop from the window was not one to be taken in cold blood. It was
taken, nevertheless, side by side and at hurtling speed by Mr. Wriford and
by Mr. Puddlebox through each half of the casement; and this done, and the
concussion recovered from, the farm surroundings which divided them
from the road were taken also at headlong bounds accelerated when
midway across by a loud crash and by ferocious view-hulloas from the
window.

The boundary hedge was gained. There was presented to the fugitives a
roadside inn having before it, travel-stained, throbbing, and unattended, a
very handsome touring motor-car. There was urged upon their resources as
they jumped to the road the sight of two men red-hot in their rear and, more
alarmingly, three led by the milky corduroy short-cutting towards their
flank.

"Blink!" gasped Mr. Puddlebox. "Blink! Hide!" and ran two bewildered
paces up the road and three distracted paces down it.

"Hide where?" panted Mr. Wriford, his wits much shaken by his run, by
the close sight of the pursuit, and more than ever by Mr. Puddlebox
bumping into him as he turned in his first irresolution and colliding with
him again as he turned in his second.
"Blink!—Here," cried Mr. Puddlebox, made a dash at the motor-car—
Mr. Wriford in bewildered confusion on his heels—opened the door, and
closing it behind them, crouched with Mr. Wriford on the floor.

"Run for it the opposite way as soon as they pass us," said Mr.
Puddlebox. "This is a very devil of a business, and I will challenge—Here
they come!"

But, quicker than they, came also another, and he from the inn. This was
a young man in livery of a chauffeur, who emerged very hurriedly wiping
his mouth and telling the landlord who followed him: "My gov'nor won't be
half wild if I ain't there by two o'clock." With which he jumped very nimbly
to his wheel, released his clutch, and with no more than a glance at the
milky corduroy and his friends who now came baying down the hedge, was
in a moment bearing Mr. Puddlebox and Mr. Wriford at immense speed
towards wherever it was that his impatient gov'nor awaited him.

Mr. Wriford put his hands to his head and said, more to himself than to
Mr. Puddlebox: "Well, this is the most extraordinary—"

Mr. Puddlebox settled his back against the seat, and cocking a very
merry eye at Mr. Wriford, chanted with enormous fervour:

"O ye motors of the Lord, bless ye the Lord: praise Him and magnify
Him for ever."
CHAPTER VIII

FIRST PERSON EXTRAORDINARY

"Well—" said Mr. Wriford to himself.

There is to be added here, as bringing Mr. Wriford to this exclamation,


that at midday the chauffeur, having whirled through rural England at great
speed for some hours on end, again drew up at a roadside inn no less
isolated than that at which he had first accommodated his passengers, and
had no sooner repaired within than Mr. Puddlebox, first protruding a
cautious head and finding no soul in sight, then led out the way through the
further door and then up the road until a friendly hedgeside invited them to
rest and to the various foods which Mr. Puddlebox had brought from the
farm and now produced from his pockets.

Mr. Wriford ate in silence, and nothing that Mr. Puddlebox could say
could fetch him from his thoughts. "Well," thought Mr. Wriford, "this is the
most extraordinary state of affairs! A week ago I was an editor in London
and afraid of everything and everybody. Now I've been in the river, and I've
stolen a ride in a wagon, and I've had a devil of a fight with a wagoner, and
I've kicked a policeman head over heels bang into a ditch, and I've nearly
been burnt alive, and I've broken out through the roof of a barn and fallen a
frightful buster off it, and I've slung a chap into a pond, and I've nearly
killed a chap and half-drowned him in milk, and I've nailed a man to the
floor by his nightshirt, and I've jumped out of a high window and been
chased for my life, and I've stolen a ride in a motor-car, and where the devil
I am now I haven't the remotest idea. Well, it's the most extraordinary—!"
BOOK THREE

ONE OF THE FRIGHTENED ONES

CHAPTER I

BODY WORK

It was in early May that Mr. Wriford cast himself into the river.
Declining Summer, sullied in her raiment by September's hand, slain by
October's, found him still in Mr. Puddlebox's company. But a different
Wriford from him whom that jolly gentleman had first met upon the road
from Barnet. In body a harder man, what of the open life, the mad
adventures, and of the casual work—all manual work—in farm and field
that supplied their necessaries when these ran short. And harder man in
soul. "You're a confirmed rascal, sir," addressed him the chairman of a
Bench of country magistrates before whom—and not their first experience
of such—he and Mr. Puddlebox once were haled, their offence that they had
been found sleeping in the outbuildings of a rural parsonage.

The rector, a gentleman, appearing unwillingly to prosecute, pleaded for


the prisoners. A trivial offence, he urged—a stormy night on which he
would gladly have given them shelter had they asked for it, and he turned to
the dock with: "Why did you not come and ask for it, my friend?"

"Why, there'd have been no fun in doing that!" said Mr. Wriford.
"Fun!" exclaimed the rector. "No, no fun perhaps. But a hearty welcome
I—"

"Oh, keep your hearty welcomes to yourself!" cried Mr. Wriford.

And then the chairman: "You're a confirmed rascal, sir. A confirmed and
stubborn rascal. When our good vicar—"

"Well, you're a self-important, over-fed, and very gross-looking


pomposity," returned Mr. Wriford.

"Seven days," said the chairman, very swollen. "Take them away,
constable."

"Curse me," said Mr. Puddlebox when, accommodated for the night in
adjoining cells, they conversed over the partition that divided them. "Curse
me, you're no better than a fool, loony, and I challenge any man to be a
bigger. Here we are at these vile tasks for a week and would have got away
scot free and a shilling from the parson but for your fool's tongue."

"Well, I had to say something to stir them up," explained Mr. Wriford. "I
must be doing something all the time, or I get—

"Well, there's better things to do than this cursed foolishness," grumbled


Mr. Puddlebox.

"It's new to me," said Mr. Wriford. "That's what I want."

That indeed was what he wanted in these months and ever sought with
sudden bursts of fierceness or of irresponsible prankishness. He must be
doing something all the time and doing something that brought reprisals,
either in form of fatigue that followed hard work in their odd jobs—
digging, carting stable refuse, hoeing a long patch of root crops, harvesting
which gave the pair steady employment and left them at the turn of the year
with a stock of shillings in hand, roadside work where labour had fallen
short and a builder was behindhand with a contract for some cottages—or
in form of punishment such as followed his truculence before the magistrate
or was got by escapades of the nature of their early adventures.
Something that brought reprisals, something to be felt in his body. "Why,
you don't understand, you see," Mr. Wriford would cry, responsive to
remonstrance from Mr. Puddlebox. "All my life I've felt things here—here
in my head," and he would strike his head hard and begin to speak loudly
and very fiercely and quickly, so that often his words rolled themselves
together or were several times repeated. "In my head, head, head—all
mixed up and whirling there so I felt I must scream to let it all out: scream
out senseless words and loud roars like
uggranddlearrrrohohohgarragarragaddaurrr! Now my head's empty, empty,
empty, and I can smash at it as if it didn't belong to me. Look here!"

"Ah, stop it, boy, stop it!" Mr. Puddlebox would cry, and catch at Mr.
Wriford's fist that banged in illustration.

"Well, that's just to show you. Man alive, I've stood sometimes in my
office with my head in such a whirling crash, and feeling so sick and
frightened—that always went with it—that I've felt I must catch by the
throat the next man who came in and kill him dead before he could speak to
me. In my head, man, in my head—felt things all my life in my head: and in
my heart;" and Mr. Wriford would strike himself fiercely upon his breast.
"Felt things in my heart so I was always in a torment and always tying
myself up tighter and tighter and tighter—not doing this because I thought
it was unkind to this person; and doing that because I thought I ought to do
it for that person—messing, messing, messing round and spoiling my life
with rotten sentiment and rotten ideas of rotten duty. God, when I think of
the welter of it all! Now, my boy, it's all over! My head's as empty as an
empty bucket and so's my heart. I don't care a curse for anybody or
anything. I'm beginning to do what I ought to have done years ago—enjoy
myself. It's only my body now; I want to ache it and feel it and hurt it and
keep it going all the time. If I don't, if I stop going and going and going, I
begin to think; and if I begin to think I begin to go back again. Then up I
jump, my boy, and let fly at somebody again, or dig or whatever the work
is, as if the devil was in me and until my body is ready to break, and then I
say to my body: 'Go on, you devil; go on. I'll keep you at it till you drop.
You've been getting soft and rotten while my head was working and driving
me. Now it's your turn. But you don't drive me, my boy; I drive you. Get at
it!' That's the way of it, Puddlebox. I'm free now, and I'm enjoying myself,
and I want to go on doing new things and doing them hard, always and all
the time. Now then!"

Mr. Puddlebox: "Sure you're enjoying yourself, boy?"

"Why, of course I am. When it was all this cursed head and all worry I
didn't belong to myself. Now it's all body, and I'm my own. I've missed
something all my life. Now I'm finding it. I'm finding what it is to be happy
—it's not to care. That's the secret of it."

Mr. Puddlebox would shake his head. "That's not the secret of it, boy."

"What is, then?"

"Why, what I've told you: not to think so much about yourself."

"Well, that's just what I'm doing. I'm not caring a curse what happens to
me."

"Yes, and thinking about that all the time. That's just where you're
spooked, boy."

"Spooked!" Mr. Wriford would cry with an easy laugh. "That's seeing
myself like I used to. I've not seen myself for weeks—months."

"But you're not unspooked yet, boy," Mr. Puddlebox would return.

II

They were come west in their tramping—set in that quarter by the


motor-car that had run them from that early adventure with the nightshirted
and the corduroyed gentlemen. It had alighted them in Wiltshire, and they
continued, while splendid summer in imperial days and pageant nights
attended them, by easy and haphazard stages down into Dorset and thence
through Somerset and Devon into Cornwall by the sea.
Many amazements in these counties and in these months—some of a
train with those afforded by the liver-cutting wagoner and by the yellow-
toothed farmer bent upon arson; some quieter, but to Mr. Wriford, if he
permitted thought, not less amazing—as when he found himself working
with his hands and in his sweat for manual wages; some in outrage of law
and morals that had shocked the Mr. Wriford of the London days. He must
be doing something, as he had told Mr. Puddlebox, and doing something all
the time. What he did not tell was that these things—when they were wild,
irresponsible, grotesque, wrong, immoral—-were done by conscious effort
before they were entered upon. Mr. Wriford used to—had to—dare himself
to do them. "Now, here you are!" Mr. Wriford would say to himself when
by freakish thought some opportunity offered itself. "Here you are! Ah, you
funk it! I knew you would. I thought so. You funk it!" And then, thus
taunted, would come the sudden burst of fierceness or of irresponsible
prankishness, and Mr. Wriford would rush at the thing fiercely, and fiercely
begin it, and with increasing fierceness carry it to settlement—one way or
the other.

Once, up from a roadside to a labourer who came sturdily by, "I'll fight
you for tuppence!" cried Mr. Wriford, facing him. "Ba goom, I'll faight thee
for nowt!" said the man and knocked him down, and when again he rushed,
furious and bleeding, smashed him again, and laughing at the ease of it, trod
on his way.

"Well, why to the devil did you do such a mad thing?" said Mr.
Puddlebox, awakened from a doze and tending Mr. Wriford's hurts. "Where
to the devil is the sense of such a thing?"

"I thought of it as he came along," said Mr. Wriford, "and I had to do it."

"Why, curse me," cried Mr. Puddlebox, "I mustn't even sleep for your
madness, boy."

"Well, I've done it," Mr. Wriford returned, much hurt but fiercely glad.
"I've done it, and I'm happy. If I hadn't—oh, you wouldn't understand.
That's enough. Let it bleed. Let the damned thing bleed. I like to see it."
He used to like to sit and count his bruises. He used to like, after hard
work on some employment, to sit and reckon which muscles ached him
most and then to spring up and exercise them so they ached anew. He used
to like to sit and count over and over again the money that their casual
labours earned him. These—bruises, and aches and shillings—were the
indisputable testimony to his freedom, to the fact that he at last was doing
things, to the reprisals against which he set his body and full earned. He
used to like to go long periods without food. He used to like, when rain fell
and Mr. Puddlebox sought shelter, to stand out in the soak of it and feel its
soak. These—fastings and discomforts—were manifests that his body was
suffering things, and that he was its master and his own.

Through all these excesses—checking him in many, from many


dissuading him, in their results supporting him—Mr. Puddlebox stuck to
him. That soft, fat, kindly and protective hand came often between him and
self-invited violence from strangers by Mr. Puddlebox—when Mr. Wriford
was not looking—tapping his head and accompanying the sign with nods
and frowns in further illustration, or by more active rescues from his
escapades. Chiefly Mr. Puddlebox employed his unfailing good-humour as
deterrent of Mr. Wriford's fierceness. He learnt to let the starvation, or the
exposure to the elements, or the engagement in some wild escapade, go to a
certain pitch, then to argue with Mr. Wriford until he made him angry, then
by some jovial whimsicality to bring him against his will to involuntary
laughter; then Mr. Wriford would be pliable, consent to eat, to take shelter,
to cease his folly. Much further than this Mr. Puddlebox carried the
affection he had conceived for Mr. Wriford—and all it cost him. Once when
lamentably far gone in his cups, he was startled out of their effects by
becoming aware that Mr. Wriford was producing from his pockets articles
that glistened beneath the moon where it lit the open-air resting-place to
which he had no recollection of having come.

He stared amazed at two watches, a small clock, spoons, and some silver
trinkets; and soon by further amazement was completely sobered. "I've
done it," said Mr. Wriford, and in his eyes could be seen the gleam, and in
his voice heard the nervous exaltation, that always went with
accomplishment of any of his fiercenesses. "I've done it! It was a devil of a
thing—right into two bedrooms—but I've done it."
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like