100% found this document useful (5 votes)
28 views

Python Descriptors: Understanding and Using the Descriptor Protocol 1st Edition Jacob Zimmerman - The full ebook with all chapters is available for download now

The document promotes a collection of ebooks available for download at textbookfull.com, including titles on Python programming and descriptors by Jacob Zimmerman. It provides links to various books that cover topics such as asynchronous programming, computation, and supervised learning using Python. The document also includes information about the authors and technical reviewers of the featured books.

Uploaded by

heinzedhrup
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 (5 votes)
28 views

Python Descriptors: Understanding and Using the Descriptor Protocol 1st Edition Jacob Zimmerman - The full ebook with all chapters is available for download now

The document promotes a collection of ebooks available for download at textbookfull.com, including titles on Python programming and descriptors by Jacob Zimmerman. It provides links to various books that cover topics such as asynchronous programming, computation, and supervised learning using Python. The document also includes information about the authors and technical reviewers of the featured books.

Uploaded by

heinzedhrup
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/ 67

Explore the full ebook collection and download it now at textbookfull.

com

Python Descriptors: Understanding and Using the


Descriptor Protocol 1st Edition Jacob Zimmerman

https://textbookfull.com/product/python-descriptors-
understanding-and-using-the-descriptor-protocol-1st-edition-
jacob-zimmerman/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Python Descriptors 1st Edition Jacob Zimmerman

https://textbookfull.com/product/python-descriptors-1st-edition-jacob-
zimmerman/

textbookfull.com

Using Asyncio in Python Understanding Python s


Asynchronous Programming Features Caleb Hattingh

https://textbookfull.com/product/using-asyncio-in-python-
understanding-python-s-asynchronous-programming-features-caleb-
hattingh/
textbookfull.com

Introduction to Computation and Programming Using Python


with Application to Understanding Data Guttag

https://textbookfull.com/product/introduction-to-computation-and-
programming-using-python-with-application-to-understanding-data-
guttag/
textbookfull.com

Introduction to Computation and Programming Using Python


With Application to Understanding Data Second Edition John
V. Guttag
https://textbookfull.com/product/introduction-to-computation-and-
programming-using-python-with-application-to-understanding-data-
second-edition-john-v-guttag/
textbookfull.com
Supervised Learning with Python Concepts and Practical
Implementation Using Python 1st Edition Vaibhav Verdhan

https://textbookfull.com/product/supervised-learning-with-python-
concepts-and-practical-implementation-using-python-1st-edition-
vaibhav-verdhan/
textbookfull.com

Supervised Learning with Python: Concepts and Practical


Implementation Using Python Vaibhav Verdhan

https://textbookfull.com/product/supervised-learning-with-python-
concepts-and-practical-implementation-using-python-vaibhav-verdhan/

textbookfull.com

Chemical and Biomedical Engineering Calculations Using


Python 1st Edition Jeffrey J. Heys

https://textbookfull.com/product/chemical-and-biomedical-engineering-
calculations-using-python-1st-edition-jeffrey-j-heys/

textbookfull.com

Computational Nuclear Engineering and Radiological Science


Using Python 1st Edition Ryan Mcclarren

https://textbookfull.com/product/computational-nuclear-engineering-
and-radiological-science-using-python-1st-edition-ryan-mcclarren/

textbookfull.com

Introduction To Computing And Problem Solving Using Python


1st Edition E. Balaguruswamy

https://textbookfull.com/product/introduction-to-computing-and-
problem-solving-using-python-1st-edition-e-balaguruswamy/

textbookfull.com
Python
Descriptors
Understanding and Using the
Descriptor Protocol

Second Edition

Jacob Zimmerman
Python Descriptors
Understanding and Using
the Descriptor Protocol
Second Edition

Jacob Zimmerman
Python Descriptors: Understanding and Using the Descriptor Protocol
Jacob Zimmerman
New York, USA

ISBN-13 (pbk): 978-1-4842-3726-7 ISBN-13 (electronic): 978-1-4842-3727-4


https://doi.org/10.1007/978-1-4842-3727-4
Library of Congress Control Number: 2018960194
Copyright © 2018 by Jacob Zimmerman
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233
Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint, paperback, or
audio rights, please email [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub via the book’s product page, located at www.apress.com/
9781484237267. For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
Table of Contents
About the Author��������������������������������������������������������������������������������vii

About the Technical Reviewer�������������������������������������������������������������ix


Acknowledgments�������������������������������������������������������������������������������xi
Introduction���������������������������������������������������������������������������������������xiii

Part I: About Descriptors�������������������������������������������������������������1


Chapter 1: What Is a Descriptor?����������������������������������������������������������3
Data Descriptors versus Non-Data Descriptors����������������������������������������������������4
The Use of Descriptors by Python�������������������������������������������������������������������������4
Summary��������������������������������������������������������������������������������������������������������������5

Chapter 2: The Descriptor Protocol������������������������������������������������������7


The __get__(self, instance, owner) Method����������������������������������������������������������7
The __set__(self, instance, value) Method��������������������������������������������������������� 8
The __delete__(self, instance) Method�����������������������������������������������������������������9
Summary������������������������������������������������������������������������������������������������������������10

Chapter 3: What Are Descriptors Good For?���������������������������������������11


Pros of Python Descriptors���������������������������������������������������������������������������������11
Encapsulation������������������������������������������������������������������������������������������������11
Reuse of Read/Write Patterns�����������������������������������������������������������������������12
Writing for the Class Level�����������������������������������������������������������������������������13

iii
Table of Contents

Cons of Python Descriptors���������������������������������������������������������������������������������13


Encapsulation������������������������������������������������������������������������������������������������13
Can Be Difficult To Write��������������������������������������������������������������������������������14
Additional Objects�����������������������������������������������������������������������������������������14
Summary������������������������������������������������������������������������������������������������������������14

Chapter 4: Descriptors in the Standard Library����������������������������������15


The property Class����������������������������������������������������������������������������������������������16
The classmethod Descriptor�������������������������������������������������������������������������������18
The staticmethod Descriptor�������������������������������������������������������������������������������19
Regular Methods�������������������������������������������������������������������������������������������������19
Summary������������������������������������������������������������������������������������������������������������20

Chapter 5: Attribute Access and Descriptors�������������������������������������21


Instance Access��������������������������������������������������������������������������������������������������22
Set and Delete Calls��������������������������������������������������������������������������������������������27
The Reasoning Behind Data versus Non-Data Descriptors��������������������������������28
Summary������������������������������������������������������������������������������������������������������������28

Part II: Making Descriptors�������������������������������������������������������29


Chapter 6: Which Methods Are Needed?��������������������������������������������31
When __get__() Is Called Without an instance Argument����������������������������������32
Raise Exception or Return self����������������������������������������������������������������������32
“Unbound” Attributes������������������������������������������������������������������������������������33
Summary������������������������������������������������������������������������������������������������������������37

Chapter 7: Storing the Attributes�������������������������������������������������������39


Class-Level Storage��������������������������������������������������������������������������������������������39
Storing Data on the Descriptor����������������������������������������������������������������������������40
Storing on the Instance Dictionary����������������������������������������������������������������46

iv
Table of Contents

Asking for the Location����������������������������������������������������������������������������������48


Indirectly Asking for the Location�����������������������������������������������������������������������50
Name Mangling���������������������������������������������������������������������������������������������51
Store the Original and the Mangled���������������������������������������������������������������54
Summary������������������������������������������������������������������������������������������������������������57

Chapter 8: Read-Only Descriptors������������������������������������������������������59


Set-Once Descriptors������������������������������������������������������������������������������������������60
Secret-Set Descriptors����������������������������������������������������������������������������������������61
Forced-Set Descriptors���������������������������������������������������������������������������������������62
Class Constants��������������������������������������������������������������������������������������������������63
Summary������������������������������������������������������������������������������������������������������������65

Chapter 9: Writing__delete__()�����������������������������������������������������������67
Summary������������������������������������������������������������������������������������������������������������68

Chapter 10: Descriptors Are Classes Too��������������������������������������������69


Inheritance����������������������������������������������������������������������������������������������������������69
More Methods�����������������������������������������������������������������������������������������������������70
Optional/Default Parameters�������������������������������������������������������������������������������70
Descriptors on Descriptors���������������������������������������������������������������������������������70
Passing an Instance Around��������������������������������������������������������������������������������71
Descriptors Just Abstract Method Calls��������������������������������������������������������������72
Summary������������������������������������������������������������������������������������������������������������72

Chapter 11: Reusing the Wheel����������������������������������������������������������73


Storage Solutions������������������������������������������������������������������������������������������������73
Read-Only Solutions��������������������������������������������������������������������������������������������76
Simple Unbound Attributes���������������������������������������������������������������������������������78
Summary������������������������������������������������������������������������������������������������������������80

v
Table of Contents

Chapter 12: Instance-Level Descriptors���������������������������������������������81


Properties in Other Languages���������������������������������������������������������������������������81
Back to Python����������������������������������������������������������������������������������������������������82
Attempt 1�������������������������������������������������������������������������������������������������������82
Attempt 2�������������������������������������������������������������������������������������������������������83
Attempt 3�������������������������������������������������������������������������������������������������������85
Attempt 4�������������������������������������������������������������������������������������������������������85
Example��������������������������������������������������������������������������������������������������������������87
Go Nuts���������������������������������������������������������������������������������������������������������������88

Chapter 13: Other Uses of Descriptors In the World���������������������������89


SQLAlchemy��������������������������������������������������������������������������������������������������������89
Jigna�������������������������������������������������������������������������������������������������������������������90
Elk�����������������������������������������������������������������������������������������������������������������������90
Validators������������������������������������������������������������������������������������������������������������91
Summary������������������������������������������������������������������������������������������������������������91

Bibliography���������������������������������������������������������������������������������������93

Index���������������������������������������������������������������������������������������������������95

vi
About the Author
Jacob Zimmerman is a blogger, gamer (tabletop more so than video
games), and programmer who was born and raised in Wisconsin. He has a
twin brother who could also be considered to have all those traits.
Jacob has his own programming blog that focuses on Java, Kotlin,
and Python programming, called “Programming Ideas with Jake”. He also
writes for a gaming blog with his brother-in-law called the “Ramblings of
Jacob and Delos”.
His brother writes a JavaScript blog called JoeZimJS and works with
his best friend on a gaming YouTube channel called “Bork & Zim Gaming,”
which Jacob helps out with on occasion.
Programming Ideas with Jake
http://programmingideaswithjake.wordpress.com/
Ramblings of Jacob and Delos
http://www.ramblingsofjacobanddelos.com/
JoeZimJS
http://www.joezimjs.com

vii
About the Technical Reviewer
Michael Thomas has worked in software development for more than 20
years as an individual contributor, team lead, program manager, and vice
president of engineering. Michael has more than 10 years of experience
working with mobile devices. His current focus is in the medical sector,
using mobile devices to accelerate information transfer between patients
and health care providers.

ix
Acknowledgments
In order to be sure that I got everything right—it would really suck for a
“comprehensive guide” to be missing a big chunk of functionality or to get
anything wrong—I enlisted the help of some Python experts on the first
edition. In return for their help, I let them introduce themselves to you
here. That’s not all I did in return, but it’s all you’re going to see :)
Emanuel Barry is a self-taught Python programmer who loves pushing
the language to its limits as well as exploring its darkest corners. He has to
do a lot of proofreading and editing for a local non-for-profit organization,
and decided to combine his love of Python and knowledge sharing with
his background in proofreading to help make this book even better. He can
often be found in the shadows of the mailing lists or the issue tracker, as
well as the Python IRC channel, as Vgr.
Chris Angelico has played around with Python since the late 90s, getting
more serious with the language in the mid 2000s. As a PEP Editor and active
participant in the various mailing lists, he keeps well up to date with what’s
new and upcoming in the language and also shares that knowledge with
fledgling students in the Thinkful tutoring/mentoring program. When not
coding in Python, he is often found wordsmithing for a Dungeons & Dragons
campaign, or exploring the linguistic delights of Alice in Wonderland and
similar works. If you find a subtle Alice reference in this text, blame him!

https://github.com/Rosuav

Kevin Mackay is a software engineer who has been programming in


Python since 2010 and is currently working at BBC, improving the Taster
platform. He is enthusiastic about open source software and occasionally
contributes to the 3D graphics application, Blender. He can be found on the
Python IRC channel as yakca or hiking on a mountain somewhere in Scotland.

xi
Introduction
Python is a remarkable language with many surprisingly powerful features
baked into it. Generators, metaclasses, and decorators are some of those,
but this book is all about descriptors.

Code Samples
All code samples are written in Python 3, since that is the most recent
version, but all the ideas and principles taught in this book apply to Python
2 as well, as long as you’re using new style classes.

The Descriptor Tools Library


Written alongside this book was a library, called descriptor-tools, which
can be installed with pip. It contains the fruition of a lot of the ideas and
helpers to make it easier to implement them all. It’s an open source project
with a public GitHub repository.1

Note Superscript letters like the one at the end of the previous line
are in reference to the bibliography at the back of the book, which
includes URLs to the referenced site.

xiii
Introduction

Conventions in This Book


When the text mentions “class” and “instance” in a general sense, they
refer to a class that has a descriptor attribute and to instances of such
classes, respectively. All other classes and instances will be referred to
more specifically.

New in the 2nd Edition


The 2nd edition is an update including new features of Python as well as
new ideas to learn. One of the new things is incredibly important if this
book wants to maintain the status of “comprehensive” guide that it strives
for. This important addition is about the addition of __set_name__() to the
descriptor protocol in Python 3.6. You can read about this in Chapter 7,
“Storing the Attributes”.
Another addition is an idea that was inspired by looking into the
__set_name__() addition to the protocol, which you’ll see just after the
section on that addition. Also, I added a chapter on creating instance-level
descriptors, which were added to descriptor-tools well before this edition
really got started.
The next thing is actually a change, not an addition. Since writing
the first book, I found out about the built-in function vars(). Calling
vars(obj) is equivalent to obj.__dict__, but is more Pythonic. Kind of
like calling len(obj) instead of obj.__len__(). So the code examples
have been updated to use vars(). Any remaining references to __dict__
are purposeful.
Pretty much everything else new in this edition is just cleaning up the
language to be more legible.

xiv
PART I

About Descriptors
Part I is a deep explanation of what descriptors are, how they work, and
how they’re used. It gives enough information that you should be able to
look at any descriptor and understand how it works and why it works that
way, assuming the writer of the code made the code legible enough.
Creating your own descriptors isn’t difficult once you have the
information from Part I, but little to no guidance is given to help with
it. Instead, Part II covers that with a bunch of options for creating new
descriptors, as well as tips for avoiding common mistakes.
CHAPTER 1

What Is a Descriptor?
Put very simply, a descriptor is a class that can be used to call a method
with simple attribute access, but there’s obviously more to it than that. It’s
difficult to explain beyond that without digging a little into how descriptors
implemented. So, here’s a high-level view of the descriptor protocol.
A descriptor implements at least one of these three methods:
__get__(), __set__(), or __delete__(). Each of those methods has a list
of parameters needed, which will be discussed a little later, and each is
called by a different sort of access of the attribute the descriptor represents.
Doing simple a.x access will call the __get__() method of x; setting the
attribute using a.x = value will call the __set__() method of x; and using
del a.x will call, as expected, the __delete__() method of x.

Note Since version 3.6, there’s another method that descriptors


can take advantage of, called __set_name__(), but using just
that method doesn’t make it a descriptor the way any of the other
three will. This method will be mostly ignored for a while, since it
doesn’t have as big a role into how descriptors work. It will only be
mentioned where most relevant.

As stated, only one of the methods needs to be implemented in


order to be considered a descriptor, but any number of them can be
implemented. And, depending on descriptor type and on which methods

© Jacob Zimmerman 2018 3


J. Zimmerman, Python Descriptors, https://doi.org/10.1007/978-1-4842-3727-4_1
Chapter 1 What Is a Descriptor?

are implemented, not implementing certain methods can restrict certain


types of attribute access or provide interesting alternative behaviors for
them. There are two types of descriptors based on which sets of these
methods are implemented: data and non-data.

 ata Descriptors versus Non-Data


D
Descriptors
A data descriptor implements at least __set__() or __delete__(), but
can include both. Data descriptors also often include __get__() since it’s
rare to want to set something without also being able to get it too. You can
get the value, even if the descriptor doesn’t include __get__(), but it’s
either roundabout or the descriptor writes it to the instance. That will be
discussed more later.
A non-data descriptor only implements __get__(). If it adds a __set__()
or __delete__() method, it becomes a data descriptor.
Unfortunately, the PyPy interpreter (up to version 2.4.0) gets this a little
bit wrong. It doesn’t take __delete__() into consideration until it knows
that it’s a data descriptor, and PyPy doesn’t believe something is a data
descriptor unless __set__() is implemented. Luckily, since a huge majority
of data descriptors implement __set__(), this rarely becomes a problem.
It may seem like the distinction is pointless, but it is not. It comes into
play upon attribute lookup. This will be discussed more later, but basically,
the distinction is the types of uses it provides.

The Use of Descriptors by Python


It is worth noting that descriptors are an inherent part of how Python
works. Python is known to be a multi-paradigm language, and as such
supports paradigms such as functional programming, imperative

4
Chapter 1 What Is a Descriptor?

programming, and object-oriented programming. This book does not


attempt to go into depth about the different paradigms; only the object-­
oriented programming paradigm will be observed. Descriptors are used
implicitly in Python for the language’s object-oriented mechanisms. As will
be explained shortly, methods are implemented using descriptors. As you
may guess from reading this, it is thanks to descriptors that object-oriented
programming is possible in Python. Descriptors are very powerful and
advanced, and this book aims to teach Python programmers how to use
them fully.

Summary
As you have seen, descriptors occupy a large part of the Python language, as
they can replace attribute access with method calls, and even restrict which
types of attribute access is allowed. Now that you have a broad idea of how
descriptors are implemented as well as their use by the language, we will
dig a little deeper yet, gaining a better understanding of how they work.

5
CHAPTER 2

The Descriptor
Protocol
In order to get a better idea of what descriptors are good for, let’s finish
showing the full descriptor protocol. It’s time to see the full signatures of
the protocol’s methods and what the parameters are.

The __get__(self, instance, owner) Method


This method is clearly the method for retrieving whatever data or object the
descriptor is meant to maintain. Obviously, self is a parameter, since it’s a
method. Also, it receives instance and/or owner. We’ll start with owner.
owner is the class that the descriptor is accessed from, or else the
class of the instance it’s being accessed from. When you make the call
A.x (A being a class), and x is a descriptor object with __get__(), it’s called
with an owner with the instance set to None. So the lookup gets effectively
transformed into A.__dict__['x'].__get__(None, A). This lets the
descriptor know that __get__() is being called from a class, not an instance.
owner is also often written to have a default value of None, but that’s largely
an optimization that only built-in descriptors take advantage of.
Now, onto the last parameters. instance is the instance that the
descriptor is being accessed from, if it is being accessed from an instance.
As previously stated, if None is passed into instance, the descriptor knows

© Jacob Zimmerman 2018 7


J. Zimmerman, Python Descriptors, https://doi.org/10.1007/978-1-4842-3727-4_2
Chapter 2 The Descriptor Protocol

that it’s being called from the class level. But, if instance is not None, then it
tells the descriptor which instance it’s being called from. So an a.x call will
be effectively translated to type(a).__dict__['x'].__get__(a, type(a)).
Notice that it still receives the instance’s class. Notice also that the call still
starts with type(a), not just a, because descriptors are stored on classes.
In order to be able to apply per-instance as well as per-class functionality,
descriptors are given instance and owner (the class of the instance). How
this translation and application happens will be discussed later.
Remember—and this applies to __set__() and __delete__() as
well—self is an instance of the descriptor itself. It is not the instance that
the descriptor is being called from; the instance parameter is the instance
the descriptor is being called from. This may sound confusing at first, but
don’t worry if you don’t understand for now—everything will be explained
further.
The __get__() method is the only one that bothers to get the class
separately. That’s because it’s the only method on non-data descriptors,
which are generally made at a class level. The built-in decorator
classmethod is implemented using descriptors and the __get__()
method. In that case, it will use the owner parameter alone.

The __set__(self, instance, value) Method


As mentioned, __set__() does not have an owner parameter that accepts
a class. __set__() does not need it, since data descriptors are generally
designed for storing per-instance data. Even if the data is being stored on a
per-class level, it should be stored internally without needing to reference
the class.
self should be self-explanatory now; the next parameter is instance.
This is the same as it is in the __get__() method. In this case, though,
your initial call is a.x = someValue, which is then translated into
type(a).__dict__['x'].__set__(a, someValue).

8
Chapter 2 The Descriptor Protocol

The last parameter is value, which is the value the attribute is being
assigned.
One thing to note: when setting an attribute that is currently a
descriptor from the class level, it will replace the descriptor with whatever
is being set. For example, A.x = someValue does not get translated to
anything; someValue replaces the descriptor object stored in x. To act on
the class, see the following note.

The __delete__(self, instance) Method


After having learned about the __get__() and __set__() methods,
__delete__() should be easy to figure out. self and instance are the
same as in the other methods, but this method is invoked when del a.x is
called and is translated to type(a).__dict__['x'].__delete__(a).
Do not accidentally name it __del__(), as that won’t work as intended.
__del__() would be the destructor of the descriptor instance, not of the
attribute stored within.
It must be noted that, again, that __delete__() does not work from the
class level, just like __set__(). Using del from the class level will remove
the descriptor from the class’ dictionary rather than calling the descriptor’s
__delete__() method.

Note If you want a descriptor’s __set__() or __delete__()


methods to work from the class level, that means that the descriptor
must be created on the class’ metaclass. When doing so, everything
that refers to owner is referring to the metaclass, while a reference
to instance refers to the class. After all, classes are just instances
of metaclasses. The section on metadescriptors will explain that in
greater detail.

9
Chapter 2 The Descriptor Protocol

Summary
That’s the sum total of the descriptor protocol. Having a basic idea of how
it works, you’ll now get a high-level view of the types of things that can be
done with descriptors.

10
CHAPTER 3

What Are Descriptors


Good For?
Nothing is perfect in this world, and Python’s descriptors are no exception.
Descriptors allow you to do some pretty cool things, but those cool things
come at a cost. Here, we discuss the good and the bad.

Pros of Python Descriptors


Obviously we’re going to go over the good things about descriptors.
Would there be an entire book about them if they couldn’t be considered a
good thing?

E ncapsulation
One of the most useful aspects of descriptors is that they encapsulate
data so well. With descriptors, you can access an attribute the simple way
using attribute access notation (a.x) while having more complex actions
happen in the background. For example, a Circle class might have radius,
diameter, circumference, and area all available as if they were attributes,
but since they’re all linked, you only need to store one (we’ll use the radius
for the example) and calculate the others based on it. But from the outside,
they all look like attributes stored on the object.

© Jacob Zimmerman 2018 11


J. Zimmerman, Python Descriptors, https://doi.org/10.1007/978-1-4842-3727-4_3
Chapter 3 What Are Descriptors Good For?

Reuse of Read/Write Patterns


Using specialized descriptors, you can reuse code that you used with
reading and/or writing of attributes. These can be used for repetitious
attributes within the same class or attribute types shared by other classes
as well. Some examples of reusable patterns are described in the following
sections.

Lazy Instantiation
You can use descriptors to define a really simple syntax for lazily
instantiating an attribute. There will be code provided for a nice lazy
attribute implementation later in the book.
In the Circle example, the non-radius attributes, after having their
caches invalidated, don’t need to calculate their values right away; they
could wait until they’re needed. That’s laziness.

Validation
Many descriptors are written simply to make sure that data being passed
in conforms to the class’ or attribute’s invariants. Such descriptors can
usually be designed as handy decorators, too.
Again with the Circle example: all of those attributes should be
positive, so all the descriptors could also make sure the value being set is
positive.

Triggering Actions
Descriptors can be used to trigger certain actions when the attribute is
accessed. For example, the observer pattern can be implemented in a
per-attribute sense to trigger calls to the observer whenever an attribute is
changed.

12
Chapter 3 What Are Descriptors Good For?

Last Circle example: all the “attributes” are based on the radius
calculated lazily. In order to keep from having to calculate them every
time, you could cache the result. Then, whenever one of them changes,
it could trigger invalidating all the others’ caches.

Writing for the Class Level


Because descriptors are stored at the class scope instead of the instance
scope, it allows you to do more robust things at the class level. For instance,
descriptors make classmethod and staticmethod work, which will be
explained in the next chapter.

Cons of Python Descriptors


As great as descriptors are, they come at a cost, just like just about
everything else in programming.

Encapsulation
Wait… encapsulation was a pro. How can it also be a con? The problem
is that you can hide incredible amounts of complexity behind something
that just looks like attribute use. With getters and setters, the user at least
sees that there’s a function being called, and plenty can happen in a single
function call. But the user won’t necessarily expect that what is seemingly
attribute access is causing something else to happen, too. Most of the time,
this isn’t a problem, but it can get in the user’s way of trying to debug any
problems, since clearly that code can’t be a problem.

13
Chapter 3 What Are Descriptors Good For?

Can Be Difficult To Write


It can be easy for the mind to get all twisted up when it comes to thinking
about the fact that descriptors are stored at the class level, but are usually
for dealing with attributes at the instance level. Besides that, there are
a lot of considerations and common pitfalls to deal with when deciding
how to save the represented attribute, whether you decide to do it on the
descriptor or on the the object that the attribute is for. The descriptor-tools
library was created specifically because of this.

Additional Objects
Because descriptors add another layer of indirection/abstraction to the
mix, they also add at least one additional object in memory, along with at
least one additional call stack level. In most cases, it’ll be more than one of
each. This adds bloat that could at least be partially mitigated using getters
and setters.

Summary
Descriptors are awesome, allowing for a variety of nice features that are
good at hiding their complexity from users of your code, but you should
definitely be aware that the power comes with cost.

14
CHAPTER 4

Descriptors in the
Standard Library
There are three basic, well-known descriptors that come with Python:
property, classmethod, and staticmethod. There’s also a fourth one that
you use all the time, but are less likely to know is a descriptor.
Of all the descriptors being shown in this chapter, it’s possible that
you only knew of property as a descriptor. Plenty of people even learn
the basics of descriptors from it, but a lot of people don’t know that
classmethod and staticmethod are descriptors. They feel like super
magical constructs built into the language that no one could reproduce in
pure Python. Once someone has an understanding of descriptors, though,
their basic implementation becomes relatively obvious. In fact, example
code will be provided for all three in simplified, pure Python code.
Lastly, it will be shown that all methods are actually implemented
with descriptors. Normal methods are actually done “magically,” since the
descriptor creation is implicit, but it’s still not entirely magical because it’s
done using a language construct the anyone could create.
What I find really interesting is that the first three are all function
decorators, which are another really awesome feature of Python that
deserves its own book, even though they’re way simpler.

© Jacob Zimmerman 2018 15


J. Zimmerman, Python Descriptors, https://doi.org/10.1007/978-1-4842-3727-4_4
Chapter 4 Descriptors in the Standard Library

The property Class


This book doesn’t include instructions for how to use the property class
and decorator; it is focused on understanding and creating descriptors.
The official documentation for using property can be found in Python’s
documentation2.
Of all the descriptors out there, property is likely the most versatile.
This is because it doesn’t really do anything on its own, but rather allows
the users to inject their wanted functionality into it by providing their own
getters, setters, and deleters.
To get a better idea of how it works, here is a simplified pure Python
implementation of property.

class property:
    def __init__(self, fget=None, fset=None, fdel=None):
        self.fget = fget
        self.fset = fset
        self.fdel = fdel

    def __get__(self, instance, owner):


        if instance is None:
            return self
        elif self.fget is None:
            raise AttributeError("unreadable attribute")
        else:
            return self.fget(instance)

    def __set__(self, instance, value):


        if self.fset is None:
            raise AttributeError("can't set attribute")
        else:
            self.fset(instance, value)

16
Chapter 4 Descriptors in the Standard Library

    def __delete__(self, instance):


        if self.fdel is None:
            raise AttributeError("can't delete attribute")
        else:
            self.fdel(instance)

    def getter(self, fget):


        return type(self)(fget, self.fset, self.fdel)

    def setter(self, fset):


        return type(self)(self.fget, fset, self.fdel)

    def deleter(self, fdel):


        return type(self)(self.fget, self.fset, fdel)

As you can now see, the property class has almost no real functionality
of its own; it simply delegates to the functions given to it. When a function
is not provided for a certain method to delegate to, property assumes that
it is a forbidden action and raises an AttributeError with an appropriate
message.
A nice thing about the property class is that it largely just accepts
methods. Even its constructor, which can be given all three methods at
once, is capable of being called with just one, or even none. Because of
this, the constructor and other methods can be used as decorators in a
very convenient syntax. Check out the documentation2 to learn more
about it.
Omitted from this code example is the doc functionality, where it sets
its own __doc__ property based on what is passed in through __init__()’s
doc parameter or using __doc__ from fget if nothing is given. Also omitted
is the code that sets other attributes on property, such as __name__, in
order to help it appear even more like a simple attribute. They did not
seem important enough to worry about, since the focus was more on the
main functionality.

17
Chapter 4 Descriptors in the Standard Library

The classmethod Descriptor


classmethod is another descriptor that can be used as a decorator, but,
unlike property, there’s no good reason not to use it as one. classmethod
is an interesting concept that doesn’t exist in many other languages
(if any). Python’s type system, which uses classes as objects, makes
classmethods easy and worthwhile to make.
Here’s the Python code for classmethod.

class classmethod:
    def __init__(self, func):
        self.func = func

    def __get__(self, instance, owner):


        return functools.partial(self.func, owner)

That’s all there is to it. classmethod is a non-data descriptor, so it only


implements __get__(). This __get__() method completely ignores the
instance parameter because, as “class” in the name implies, the method
has nothing to do with an instance of the class and only deals with the
class itself. What’s really nice is the fact that this can still be called from an
instance without any issues.
Why does the __get__() method return a functools.partial object
with the owner passed in, though? To understand this, think about the
parameter list of a function marked as a classmethod. The first parameter
is the class parameter, usually named cls. This class parameter is filled in
the call to partial so that the returned function can be called with just the
arguments the user wants to explicitly provide. The true implementation
doesn’t use partial, but works similarly.
Again, the code that sets __name__, __doc__, etc. is omitted to show
only how the main functionality works.

18
Chapter 4 Descriptors in the Standard Library

The staticmethod Descriptor


A method marked with staticmethod is strange in that it’s a method that
is really just a function, but it is “attached” to a class. Being part of the class
doesn’t do anything other than show users that it is associated with that
class and giving it a more specific namespace. Also, interestingly, because
staticmethod and classmethod are implemented using descriptors,
they’re inherited by subclasses.
The implementation of staticmethod is even simpler than that of
classmethod; it just accepts a function and then returns it when __get__()
is called.

class staticmethod:
    def __init__(self, func):
        self.func = func

    def __get__(self, instance, owner):


        return self.func

Regular Methods
Remember that it was stated earlier that regular methods implicitly use
descriptors as well. In fact, all functions can be used as methods. This is
because functions are non-data descriptors as well as callables.
Here is a Python implementation that roughly shows how a function
looks.

class function:
    def __call__(self, *args, **kwargs):
        # do something

19
Other documents randomly have
different content
In the broader valleys, where the streams are smaller, or have done
less destruction to the country, grows the giant diàdia grass, the stems
often attaining two and a half inches in circumference and a mean
height of fifteen feet; there may be found some of the richest soil in
the world. Where the diàdia has been exists the wildest luxuriance of
vegetation; palms, plantain, Indian corn, ground-nuts, yams and all
garden produce are at their best, and ever at the mercy of the
elephants, who rejoice in such choice selection. In the Majinga country
the native houses have to be scattered through their rich farms, and
morning and night the people shout, scream, and beat their drums to
frighten off these giant marauders.
It is not a forest country. Strange clumps of trees grow on the tops
of the hills, which mark the ancient plateau level, but the rich soil
beside the streams and in the snug valleys is generally well wooded.
The vegetation presents an altogether tropical appearance, the bracken
in the glades is the only thing home-like. Rich creepers drape the trees,
beautiful palms lend their rare grace, and in their seasons an endless
succession of beautiful flowers, from huge arums to a tiny crucifer of
the richest scarlet, bright creepers, pure white stephanotis-like
blossoms, rich lilies, and many other gorgeous plants, and bright
berries, not in such wild, packed profusion that the eye is bewildered
with a blaze of beauty, but here and there with sufficient interval to
permit the due appreciation of their several lovelinesses. The beauty of
the leaf-forms is alone a pleasure; while the tints from the darkest
green to soft yellow, delicate pink, bronze, chocolate, and bright
crimson are mysteries of colour. On the rocky stream banks and on the
palm stems are graceful ferns, while the lycopodium climbs the bushes,
mingled with the beautiful selaginella. The scenery of the country is
described in an unequalled manner by Mr. H. H. Johnston in his book,
The River Congo. Himself an accomplished artist, he describes as only
an artist can.
The vegetation suffers from the annual grass fires, which sweep
the country. As soon as the dry season has well set in (June) the
burning commences; in some parts it does not become general until
August. The grass is fired sometimes on a small scale by the children,
that they may hunt their rats, but the great fires occur when the
natives of a district combine for a grand hunt. For days the fire steadily
sweeps along, the game flee before it, hawks wheel above the line of
fire, catching the grasshoppers that seek to avoid the flames, while
smaller birds catch the lesser insects. The internodes of the burning
grass explode with a report like that of a pistol, and can be heard
distinctly a mile distant. Women and children follow on the line to dig
out the rats; and in the holes may be found rats, mice, snakes, and
lizards, seeking common protection from a common danger. At night
the horizon is lit up by the zigzag lines of fire, and in the daytime are
seen the thick columns of smoke slowly advancing, and filling the air
with a dull haze, which limits the horizon to ten or fifteen miles.
The climate of the Congo has been unduly vilified. In common with
all intertropical regions there is a malarial fever, which has claimed
many victims. It generally assumes an intermittent type, commencing
with an ague ‘shake;’ sometimes it is remittent, and combines with
grave symptoms. Although the precise nature of the malarial germ is
still unknown, continued study has enabled medical men to grapple
much more successfully with this great enemy. So long as it was the
custom to treat the fever with bleeding and calomel it was no wonder
that Africa was ‘the white man’s grave;’ that was not so much the fault
of Africa as the white man’s ignorance.
Traders on the coast have generally fair health, and many live to
old age. Ladies in the Mission stations and elsewhere live long on the
coast. Indeed, Dr. Laws, of Livingstonia, has expressed an opinion that
ladies, as a rule, stand the climate better than the men.
In these matters we are far readier to count up the misfortunes
than to note the large proportion of those who live long and do good
work in Africa.
New missions and scientific expeditions have paid the penalty for
ignorance and the difficulties of pioneering; but where the experience
of others can aid, and due precautions are observed, there is no reason
why the Congo should be considered more unhealthy than India
generally. It is certainly possible to live on the Congo. The writer, who
was one of the first party of the Baptist Missionary Society’s Congo
Mission, and has had five years’ pioneering work, had not a single fever
during the last two and a half years. This is rather exceptional, but
speaks well as to the possibilities. Indeed, there are many reasons why
the climate of India should be considered worse. The Indian
temperature is far higher, dysentery and cholera are annual scourges,
and liver complaints far more common.
The excellent Observations Météorologiques of Dr. A. von
Danckelman, of the International Association (Asher and Co., Berlin),
gives most interesting statistics of the Lower Congo. The highest
temperature registered by him at an elevation of 375 feet was 96·5°
Fahr., and the lowest 53°, the highest mean temperature being 83°.
The general midday temperature in the house in the hot season is
80°-85°; and at night 75°-80°. On the coast a cool breeze blows in
from the sea from about eleven o’clock in the morning; commencing
somewhat later in proportion to the distance in the interior. This same
cool sea-breeze blows freshly on the upper river, and even when high
temperatures can be taken in the sun the air is cool. Very frequently
thick clouds cover the sky and temper the heat. In this respect the
Congo compares very favourably with India, and with other parts of the
African coast. On the Congo a punkah is quite unnecessary at any time,
in a house built on a reasonable site.
The rainy season commences in the cataract region about
September 15, attaining the maxima in November and April, with a
minimum (the ‘little rains’) about Christmas time, and ceasing about
May 15. The rise of the river commences about August, for the
northern rains, culminating about January 1, when it falls rapidly until
April 1. It then rises rapidly to a second but lower maximum about May
1; it then steadily falls until August. These dates may vary a fortnight,
or even three weeks; that is to say, they may occur so much earlier, but
seldom later.
The rain generally falls at night, often with a violent tornado soon
after sundown. Heavy clouds appear on the horizon, the tornado arch
advances, the wind lulls, and with breathless suspense everything
prepares for the onslaught of the storm. A dull roar is heard. The hiss
of coming rain, fierce gusts of wind, and in a moment the deluge is
upon you. Wild wind, torrents of rain, incessant peals of thunder,
flashes of lightning every few seconds. The whole world seems to be
going to rack and ruin. After an hour or two the fury of the storm is
spent, and heavy rain continues for a while.
Considering the intensity of the electric disturbance, accidents by
lightning are rare. One or two cases only have been noted thus far: the
mission boat on the Cameroons River was struck, and three people on
board killed; a house of the International Association was fired; the
same thing occurred in a native village. Occasionally a tree is struck.

A SCENE ON THE CONGO.


Game is not by any means abundant. Several species of antelope
are found, the most common being the harnessed antelope
(Tragelaphus scriptus). Elephants are numerous in some parts, but are
very seldom hunted. Leopards are found throughout the country. There
are two species of buffaloes on the upper river; west of Stanley Pool
they are less numerous, and more confined in their distribution. The
gorilla is reported three days north of Stanley Pool. The chimpanzee
has been heard of, but not seen. Many monkeys inhabit the woods. The
jackal is not uncommon; but the lion, which was common until fifty
years ago, has disappeared over the district between the Kwangu and
the mouth of the river. Hippopotami are very numerous; three varieties
of crocodile infest the rivers. Fish in great variety are caught by the
natives in traps and nets, and by hooks and spearing. Whitebait fishing
affords occupation to many men in the cataract regions. By day they sit
on the rocks waiting for the gleam of a shoal; and when one appears,
in an instant they have divested themselves of their scanty clothes, and
rush into the strong shallow water with their nets—not unlike a
shrimper’s net—each one a little beyond the other, and often are well
rewarded for their trouble. Their take is then dried in the sun and sold
in the market.
The grey parrots fly home in the evenings in great flocks, whistling
and screaming, the happiest birds there are. There is an endless variety
of bird-life, which as the mating season nears dons brighter and more
striking colouring.
Not very promising was the aspect which the wild people dwelling
on the banks of the Congo River presented to Mr. Stanley during the
first journey through these unknown regions. As he approached a
village, the great war drums and horns thundered through the woods,
canoes were manned, and, apparently without the remotest reason,
they proceeded to attack the white man with his little flock.
Fierce, wild savagery, loathsome cannibalism, cruelty, the densest
darkness and degradation of heathenism—such was the aspect as the
two white men, with some one hundred and fifty followers,
endeavoured quietly and peaceably to paddle in midstream past the
villages.
NGOMBE WARRIOR.

We have talked with these folk about this humiliating phase of


humanity.
‘Why did you attack the mundele (white man)?’
‘We did not, but we were going to.’
‘Why? Sit down, and tell us all about it.’
This to a Zombo slave of the Bayansi of Bolobo, who had been sold
by his countrymen for ivory, when scarcely more than a baby. His
forehead scored with the tribal mark of his master, he was in bearing
and speech a thorough Mubangi, but remembered his old language, as
there are many such slaves on the upper river.
‘The news reached us,’ he said, ‘that a white man and his followers
were coming down the river. Every one above us had attacked him for
the honour and glory of having fought one of the mysterious whites we
hear of, and for whose cloth we trade. We could not let the opportunity
pass; had we done so, we should have been behind the rest, and
become the ridicule of the river. When we went to trade, and joined the
dance in friendly towns, the girls would sing how their braves had
fought the white man, while the Bolobo people had hidden in the grass
like women. We manned our canoes, and hid behind the long point
above our town; but a little above us the white man crossed to the
other side of the river. We waited to see what would happen, and soon
one of our people came from the opposite towns, and told us that the
white man was buying food, and giving beads, brass wire, and glorious
things. We quickly filled our canoes with plaintain, cassava pudding,
fowls, etc., and hurried over, and so we did not fight after all.’
That was the beginning of better days for Mr. Stanley. The story as
we heard it at Stanley Pool explains in a measure the persistent savage
attacks.
Since November, 1882, there has been a station of the
International Association at Bolobo; and the Congo Mission is hoping
shortly to occupy that populous district.

* * * * *
The inhabitants of Africa have been divided into six great races.
Their languages form the basis of such division. Mr. R. N. Cust, the
Secretary of the Royal Asiatic Society, has recently published a valuable
work on the Languages of Africa, and the coloured map accompanying
it presents the distribution of races very graphically to the eye. To the
north we find the Semitic race. In the Sahara, on the Nile, in Abyssinia
and in Somali land, a Hamitic race, speaking languages allied to
Ethiopic. From Gambia to the mouths of the Niger the Negro race, of
whom the Ashantees are types.
Interspersed among the Negro and Hamitic races are detached
peoples, speaking languages of the Nuba Fullah group, of whom the
Masai, among whom Mr. Thomson has been travelling, to the east of
the Victoria Nyanza, may be taken as types.
To the south of all these is the great Bantu (= men) race. A line
drawn eastward from the Gulf of Biafra to the Indian Ocean will mark
roughly the boundary of this greatest of the African races. Near to the
Cape of Good Hope are found the Hottentot Bushman, a degraded
race, who appear to have been the aborigines, but now driven to the
remotest corner, are still yielding to the stronger Bantus.
It is surmised that some dwarf races, said to be scattered through
the Bantu countries, may be of this aboriginal stock, but no satisfactory
opportunities have yet offered for ascertaining the truth. These dwarfs
are always a little beyond the countries visited by travellers, a few
specimens, said to belong to them, have been seen, but their country is
ever elusive. It is likely that they may prove to be degraded tribes of
the races among whom they dwell, just as the Niam Niams are believed
to be Nuba-Fullahs.
Of the Bantus the Zulu Kaffirs may be the best known types,
although they have borrowed from the Hottentots the clicks that so
much disfigure their language.
With the exception of these hypothetical dwarfs, the inhabitants of
the Congo basin are all Bantus.
As before stated, language is the basis of such classification. With
the other races they have nothing in common. In roots, grammatical
construction and all distinguishing features of language, the Bantu
dialects have a marked individuality, differing almost totally from the
other races, while showing the most marked affinities among
themselves. It would be inappropriate to burden the present paper with
a lengthy dissertation on the peculiarities of the Bantu languages. The
most marked feature is the euphonic concord, a principle by which the
characteristic prefix of the noun is attached to the pronouns and
adjectives, qualifying it, and to the verb of which it is the subject. Thus
matadi mama mampwena mampembe mejitanga beni: these great
white stones are very heavy. Quoting J. R. Wilson, Mr. Cust remarks
that ‘The Bantu languages are soft, pliant, and flexible, to an almost
unlimited extent. Their grammatical principles are founded on the most
systematic and philosophical basis, and the number of words may be
multiplied to an almost indefinite extent. They are capable of
expressing all the nicer shades of thought and feeling, and perhaps no
other languages of the world are capable of more definiteness and
precision of expression. Livingstone justly remarks that a complaint of
the poverty of the language is often only a sure proof of the scanty
attainments of the complainant. As a fact the Bantu languages are
exceedingly rich.’ My own researches fully confirm these remarks. The
question is very naturally raised, Whence do these savages possess so
fine a language? Is it an evolution now in process from something
ruder and more savage or from something inarticulate? The marked
similarity of the dialects points to a common origin; their richness,
superiority, and the regularity of the individual character maintained
over so large an area, give a high idea of the original language which
was spoken before they separated.
Heathenism is degrading, and under its influence everything is
going backwards. We are led by the evidence of the language to look
for a better, nobler origin of the race, rather than to consider it an
evolution from something infinitely lower. The Bantu languages are as
far removed from others of the continent as English is from Turkish or
Chinese. Some earlier writers have endeavoured to trace similarities,
but later research has proved that they do not exist. The origin of the
race must ever remain a mystery. What, when, and where, cannot be
ascertained, for no memorials exist in books or monuments. The Bantu
race and languages cannot be an evolution from something inferior;
they are a degradation from something superior. Coastwards there are
traditions of change and movement on the part of the people; in the
east and on the south marauding tribes and slave-hunters have
devastated large tracts of country, but there is no sign of general
movement on the part of the Bantus.
The traditions of countries along the coast where white men have
long settled speak of much greater, more powerful kingdoms in the
past; and after due allowance has been made for exaggeration, it is too
evident that the kings of Congo, Kabinda, Loango, and Angola, exerted
at one time far more influence than they do to-day. Indeed, the King of
Congo is the only chief who maintains his style and title; the others
have become extinct during this century. We find then the whole
country in a state of disintegration; every town a separate state, and its
chief, to all practical purposes, independent.
Makoko, the Teke chief with whom De Brazza made his famous
treaty, is said to have levied taxes on the north bank people near his
town. The King of Congo used to receive a tribute from the remnants
of the old Congo empire; but to-day he has to content himself with
levying a mild blackmail on passing caravans, and receives a present,
when he gives the ‘hat’ and the insignia of office to those who succeed
to chieftainships over which in olden times the kings exercised
suzerainty. Few, indeed, of those acknowledge him to-day even to that
extent.
These independent townships group themselves into tribes and
tribelets; it is, however, a matter of great difficulty to learn the tribal
names, which are best obtained from neighbours. The old Congo
empire formerly included the countries on the south bank from the
coast to Stanley Pool, and southward to the Bunda-speaking people of
Ngola (Angola), while homage was rendered by the kings of Loango
and Kabinda. To-day the influence of the king is merely nominal outside
his town. He is respected, however, in a radius of thirty or forty miles,
but seldom if ever interferes in any matters.
San Salvador is situated on a plateau 1,700 feet above the sea,
about two-and-a-half miles long by one mile wide. Broad valleys 300
feet deep surround it, and in the south flows the little river Lueji, a
tributary of the Lunda-Mpozo.
There are abundant traces of its former importance. The ruins of a
stone wall, two feet thick and fifteen feet high, encircle the town. The
ruins of the cathedral are very interesting, and show it to have been a
very fine building. The material is an ironstone conglomerate, while the
lime was burnt from rock in the neighbourhood.
Amid the strong rich grass that covers the plateau exist ruins of
some twenty-six buildings, which are said to have been churches, while
straight lines of mingomena bushes mark the sites of suburban villas
and hamlets. The story runs that the old kings kept up the population
of the Mbanza (chief town) by raids into the country. The natives of a
town forty miles away would wake up in the morning to find
themselves surrounded. As they came out of their houses they would
be killed, until there was no further show of resistance; then those who
remained would be deported to the capital and be compelled to build
there, while many would be sold to the slave-traders on the coast.
These days are for ever past. Men-of-war have so closely watched the
coast that the slave trade has languished and died, except in Angola,
where it exists under a finer name, the slave being considered a
‘Colonial,’ while Portuguese ingenuity and corruption arrange for
‘emigration’ to the islands San Thomé, Principe, and even to the
Bissagos.
While these slave raids in Congo are things of the past, a mild
domestic slavery exists among the natives. In most cases the slaves
are more like feudal retainers or serfs. A man of means invests his
money in slaves, and thereby becomes more independent, for his slave
retainers can support him in difficulties with his neighbours. It
frequently happens that he builds a stockade at a little distance from
the town in which he has been brought up, and this becomes the
nucleus of a new town. In the latter end of the rainy season and the
beginning of the ‘dries,’ they will cut nianga grass, the long six-foot
blades of which spring up out of the ground, and have no stem or
nodes. This grass is dried and used for the covering of the huts. Stems
of palm fronds are also trimmed and split. Papyrus is brought from the
marshes, and strips of its green skin twisted into string, with which
they tie together securely the posts and rafters, so that they may stand
the strain of the fierce tornadoes which sweep the country.
MANNER OF DRESSING THE HAIR.
CHAPTER IV.

Home Life on the Congo.

P
erhaps the home life of the Congo folk may be best depicted if
some familiar scenes are described.

While engaged in the transport service of the mission, I was


sitting quietly in my tent in Sadi Kiandunga’s town, when without the
least warning a volley was fired at less than a hundred yards from
my little camp. The men shouted, the women screamed, the wildest
commotion ensued. Was it an attack upon the town? What had
happened? As a man ran past the tent, I inquired the cause.
‘Oh, nothing,’ he said; ‘it is only a baby born, and everyone is
glad and shouting out their joy at the safe birth; they have fired a
feu-de-joie: don’t you do so in your country?’
The house where the little stranger had arrived was very small;
a fire was burning inside, filling it with strong wood smoke; and as if
that were not sufficient discomfort for such a time, the house was
literally crammed with women, all shouting vociferously, showing in
this well-meaning but mistaken manner their sympathy in the
mother’s joy.
The people rise at daybreak, and the fire, which has been kept
smouldering all night, is replenished, or, if it has gone out, fire is
obtained from another household. The wife clears up the ashes from
the hearth, and sweeps out the chips and husks that remain from
last night’s supper.
The husband, if a tidy man, sweeps his compound. Negro toilet
operations then ensue. A calabash of water is taken behind the
house, and filling his mouth with water Ndualu (Dom Alvaro) allows
a thin stream to flow over his hands as he carefully washes them,
also his face; then cleaning his teeth, he goes to sit in front of his
house to comb his hair. The ladies have been bestirring themselves,
and a snack of food is ready—a few roast ground-nuts, or a piece of
prepared cassava.
The infants are placed in the care of older babies, and the
women and girls of the town wend their way to the village spring,
where they bathe and gossip until all the calabashes being full they
return with the day’s supply of water. One calabash is for the baby,
who is brought outside, and carefully washed, squalling lustily as the
cold douche is poured over him. If the mother is careful, his feet are
examined for jiggers. This sand flea, brought from Brazils some
twenty years ago, is a great pest. Burrowing into the feet often in
the most tender parts, the insect swells until its eggs are mature,
when the little cyst bursts, and they are set free. If they are not
extracted the jiggers set up an inflammation, which may even
terminate in mortification. It is very common to see one or two toes
absent from this cause.
The preliminaries of the day being over, the women start for the
farms. Taking with them in the great conical basket a hoe, a little
food, and a small calabash of water, the baby is carried on the hip,
or more often made to straddle its mother’s back, and tied on with a
cloth dexterously fastened in front. So the poor child travels often
through the hot sun, bound tightly to its mother’s reeking body, its
little head but inadequately protected by its incipient wool. No
wonder that an African baby who has survived the hardships of
babyhood grows up to be strong, and able to bear great strain and
fatigue. The weaklings are early weeded out, and often poor
mothers, wringing their hands, wail and deplore the loss of the little
darling, whose death is due to their own lack of care, rather than to
the supposed witchcraft and devilish malice of some one in the
town.
The men will sometimes help in the farms when trees have to be
felled, but otherwise the women perform the farm work; and as the
ground does not need much scratching to produce a crop, the
hoeing and weeding afford them healthy employment, sufficient to
keep them so far out of mischief. We have seen towns in the
neighbourhood of Stanley Pool where the women do no farm work,
living on the proceeds of their husband’s ivory trade; they gossip,
smoke, sleep, and cook, or spend an hour or two in arranging the
coiffure of their lord or of a companion. Laziness is not good for any
folk, and where there is so little housework the gardening is not too
severe a tax on the women. Towards evening they return, bringing
some cabbage or cassava leaves, or something to make up some
little relish, and proceed to cook the evening meal.
The men have their own departments of work: they are great
traders. The Congo week consists of four days; Nkandu, Konzo,
Nhenge, Nsona, and every four or eight days they hold their
markets. As they have many markets within a moderate distance,
and occurring on different days of the week, there is generally a
market to attend on each day, if any one is so disposed. The
marketplaces are in open country, generally on a hill-top, away from
towns. These precautions prevent surprises.
On the appointed day large numbers of men, women, and
children are to be met carrying their goods. There is cassava in
various forms, dried, in puddings, or as meal; plantain, ground-nuts,
and other food-stuffs; pigs, goats, sheep, fowls and fish; dried
caterpillars on skewers; dried meat; wares from Europe; cloth,
beads, knives, guns, brass wire, salt, gunpowder. Drink in
abundance, palm wine, native beer, sometimes gin and rum. Native
produce, such as palm oil, ground-nuts, sesamum, india-rubber,
crates of fowls, bundles of native cloth, meal sieves, baskets, hoes,
etc.
Stringent laws are made to protect these markets. No one is
allowed to come armed, no one may catch a debtor on market-day,
no one may use a knife against another in a passion. The penalty for
all these offences is death, and many muzzles of buried guns stick
up in the market places to warn other rowdies against a like fate.
Between the coast and Stanley Pool beads are the currency; above
the Pool brass rods take their place. A man wishing to sell salt and to
buy india-rubber, first sells his salt for beads, and with the beads
buys the rubber. Large profits can be made on these markets, and
many natives spend the greater part of their time travelling from one
to another for the purpose of trade.
Children commence trading very early. A five-year old boy will
somehow get three or four strings of beads, and with them will buy
a small chicken. After a few months of patient care, it is worth eight
or ten strings, and his capital is doubled. He is soon able to buy a
small pig, which follows him about like a dog, and sleeps in his
house until, by and by, it fetches a good amount on the market. The
proceeds of rat hunting, barter among the town boys, and further
trade, have meanwhile increased his stock in trade. When he grows
older, he accompanies a caravan to the coast, he gets a nice present
to carry food for his uncle; en route his ideas of trade are enlarged.
He commences to buy india-rubber, and brings back with him next
time salt and cloth, a gun and some powder, a knife, and a plate.
And so by degrees he is encouraged to fresh effort, until he has
sufficient to pay for a wife or two. Continuing still in trade, he buys
and sells, investing his property in slave retainers, and hiding some
in reserve, in case of misfortune, or against his death. For it is the
ambition of all to be buried in a large quantity of cloth. Then the
report goes that so and so was buried, and that he was wound in
200 fathoms of cloth, and that 50 guns were buried with him, and so
on. This sort of burial is a Congo Westminster Abbey.
The girls help their mothers in farming and housework until they
arrive at a marriageable age. In some places they are betrothed very
early; the intended husband paying a deposit, and by instalments
completing the price demanded by the girl’s maternal relatives. The
amount is often heavy—reckoned by Congo wealth—but varies much
according to the position of the girl’s family or the suitor’s wealth. It
is altogether a business matter. Should the wife die, her maternal
relatives have to provide another wife without further payment; and
as frequently they have spent the sum paid in the first instance, they
are landed in difficulties. Palavers about women are a fruitful source
of war.
Children are considered the property of the wife’s relatives, the
father has little or no control over them. The right of inheritance is
from uncle to nephew, thus a man’s slaves and real property go to
the eldest son of his eldest sister, or the next of kin on such lines. A
wise nephew will therefore leave his father’s house, and go to live
with his uncle, whom he hopes to succeed. His uncle also, knowing
that his nephew is to inherit his goods, while his own children belong
to his wife’s clan, cares more for his nephew than his own children.
The evil of the system is recognized by many, but they cannot see
how the necessary revolution is to be brought about.
At the age of five or six the boys do not stay longer with their
mothers. Some bigger boys having built a house, the small boys just
breaking loose from parental restraints go to them, and beg to be
allowed to live with them. They in turn promise to find them in
firewood, and to be their little retainers pro tem. These boys’ houses
are called mbonge. I turned up late at night (eight o’clock) in a
native town, having made a forced march. I had never visited there
before, and not liking to rouse the chief at such an hour, I went to
the mbonge, and asked the boys whether I and my two attendants
might sleep there to save fuss and trouble, as I must be off again at
daybreak. ‘Oh, you are Ingelezo, are you? come in; yes, we are glad
to see you, so often we have heard of you, and now we see you. We
are very pleased.’ This was kindly spoken; so, stooping through the
low doorway, I entered a roomy house. Some ten boys had just
finished supper, and squatted round a smoky fire. I was glad to
stretch out on the papyrus mat they gave me, keeping low down, to
avoid the smoke which otherwise almost blinded me. I had with me
half a fowl, a small bell (1¼d.), and three strings of beads. A boy
spitted my fowl over the fire, while my attendants dozed, for they
were worn out with the long march of the day. I begged some
plantain, and a lad went to the door, and shouted, ‘Bring some
plantain to the mbonge.’ A kindly woman brought some. When my
meal was ready I asked for a pinch of salt and some water; they
shouted for these, and got them. Having finished my meal, I coiled
up in my blanket; and next morning, giving them the bell and three
strings, thanked them, and so we parted.
The boys of the mbonge are well attended to; for to get the
name of ‘stingy’ is the first step towards the terrible rumour of witch.
The constant activities of trade tend to develop the intellectual
faculties of the people. Cute, long-headed men, with wonderful
memories, having no account books or invoices, they ask you
sensible questions; and if you can speak their language, an hour’s
chat may be as pleasant with them as with some whiter and more
civilised folk. If you have a bargain to drive with them, you need all
your wits and firmness; while if they are stronger than you, or have
no reason to respect you, they will have their way.
Clever in pottery and metal work, making hoes and knives,
casting bracelets, anklets, and even bells from the brass rods of
trade, beating out brass wire, and ribbon, they strike you at once as
being of a superior type.
We might draw another picture. There are districts where there
seems to be no energy in the people. Take, for instance, the Majinga
or the Lukunga Valley, as we knew them two years ago. Here the
natives live in the midst of plenty, for the soil is not to be equalled in
richness. The proceeds of a goat sold on one of the markets will find
a large family in palm fibre cloth for a year; while a crate or two of
fowls will provide salt, gunpowder, and an occasional hoe or plate.
A boy grows up in this rich country, and for a while his intellect
expands as he learns about the little world around him. As he grows
older, he may bestir himself to find means to buy a gun, and then a
wife: that accomplished, he has practically nothing more to learn or
live for. He sleeps or smokes all day, unless about September the
grass is burnt and there is a little hunting, though a war or a palaver
may sometimes break the monotony. Otherwise, his wife cultivates
the land, and feeds him; he eats and sleeps. Living such an animal
life, his intellect stagnates, he becomes quarrelsome and stupid to a
degree almost hopeless. Dirty, he is contented to see his hut fall to
pieces almost over his head.

A CONGO NATIVE SMOKING.

The women are content often with a rag for clothing. They wear
a grass stem three inches long through the nose, and a dirty rag for
an earring. The hair is matted with a mixture of oil and vegetable
charcoal; and if a lady happen to be in mourning the same filthy
compound is smeared over her face.
With the advent of white men this sad picture has begun to
change. The Livingstone Inland Mission (American Baptists) and the
International Association have stations among them; their transport
and that of the Baptist Missionary Society (English) passes through
the country. The people are coming forward as carriers; they sell
their goats, fowls, etc., are getting cloth; and in this short time a
change for the better is apparent. Here lies all the difference
between the degraded and the higher types of the African. The
intellect of the one is stagnant, while the other has everything to
quicken it.
As children the better class will compare favourably with English
boys; bright, sharp, anxious to learn, they push on well with their
studies. Our schools are full of promise. At Stanley Pool the other
day the boys were much concerned because a new boy had
mastered his alphabet the first day. They all felt that he was too
clever.
The future of these interesting people is full of the brightest
hope. Give them the Gospel, and with it the advantages of
education, and books to read; quicken within them tastes which will
render labour a necessity and a pleasure; give them something high
and noble to work and live for; and we shall see great and rapid
changes. Christian Missions are no experiment. We have to deal with
a vigorous race that will repay all that Christian effort can do on their
behalf.
CHAPTER V.

The Religious Ideas of the Natives.

T
here is nothing that can be said to take the place of a religion
throughout the whole region of the Congo. There is no
idolatry, no system of worship; nothing but a vague
superstition, a groping in the dark, the deepest, saddest ignorance,
without a hope of light. The people have the name of God, but know
nothing further about Him. The idea is not, however, of an evil
being, or they would wish to propitiate him. A mild and gentle chief
gets little respect or honour. A man who is hard and stern, reckless
of life, is feared and respected. Hence, as they fear no evil from
God, they do not trouble themselves about Him in any way—never
even invoke Him. Perhaps it may be because they regard Him as
beyond their reach and ken, or careless of them.

Nzambi, or some slightly modified form, such as Nyambi or


Anyambie, is the name by which God is known over the explored
regions of the western portion, while the Bayansi of the upper river
use also Molongo, which is the same as Mulungu and Muungu of the
east coast. Of the derivation of Nzambi we cannot speak definitely or
even approximately. Suffice it to say that the word has a sense of
greatness, and conveys a definite idea of a Supreme Being. It
cannot be connected with a vague notion of sky, having nothing
common with the word Ezulu (heaven).
There is a decided idea of personality, and the Congos generally
speak of Nzambi-ampungu, the Most High (Supreme) God. The
name of God is all that they know, and certainly they have no notion
of any means of communication between God and man. They regard
Him as the Creator, and as the sender of rain, but would never under
any circumstances think of their voice being heard in heaven. So,
having no helper, they betake themselves to charms to avert evil and
for general protection.
The knowledge of the name of God gives us a good basis to
work upon. We can tell them that we bring them a message from
Nzambi Himself, not a story of a white man’s God, but their God and
ours, and at once we get a ready and deeply interested hearing.
‘Have we seen Nzambi? Does He live in the white man’s land
under the sea? How did we hear this news?’ Such are the questions
they are ever ready to ask.
On one occasion, at Stanley Pool, a lad from the far upper river
sold by Zombo traders to the Bayansi, asked me, ‘But, Mundele, all
joking apart, what do you really come here for if you do not want to
trade? Tell me truly.’ I told him that we had been commissioned with
the message of good news from Nzambi, and that was our real and
sole business. ‘What! Nzambi, who lives in the heavens? (Nzambi
kun’Ezulu).’ As he said this he pointed up into the sky. Poor boy! I
wondered how he knew that there was a God, and that he so
instinctively pointed up to the blue sky. I saw him once or twice after
that. He soon returned to his distant home, but could tell his people
that he had seen white men, who were coming soon to bring them a
good message from Nzambi.
They have a very decided idea of a future state, but as to what
and where the opinion is much divided. Indeed, there is not the
remotest notion that death can be a cessation of being. If any one
dies they think that some one, living or dead, has established a
connection with the unseen world, and somehow, and for some
purpose, has ‘witched away’ the deceased.
When a man is sick he first resorts to bleeding and simple
remedies. If no relief is obtained, a native doctor is called. The man’s
friends and relatives help him to pay the fee, if large. Having agreed
as to the fee, the doctor may fetch aromatic or bitter leaves from the
woods, and make a decoction of them, wring them in water, or in
some way extract their properties. Perhaps he may add a small
scraping of a snake’s head, of a few nuts or seeds, or of some
mysterious articles in his bundle of charms. There is an endless
variety of procedure.
Mr. Comber was recently watching a ‘doctoring’ at Ngombe. A
chief, Lutete, was sick, and the people were very anxious about him.
The doctor called for a fowl, a string was tied to its leg, and the
other end to Lutete’s arm. After some mysterious actions, and
placing some white marks with pipeclay upon the body of the
sufferer, he proceeded to push the complaint from the extremities
into the body, from the body into the arm, and finally succeeded in
drawing the disease down the arm, through the string, and into the
unfortunate fowl, which doubtless was little the worse for its
vicarious position, until the doctor had it killed for his evening meal.
There is far more knavery than skill in all their doctoring. If the
disease does not yield to such treatment, other doctors are called in;
and as matters become more serious, it is evidently not a simple
case of sickness, for it will not yield to skilful physicians; it must be a
case of witchcraft. The sufferer now becomes terribly anxious, and
Nganga-a-moko (the charms doctor) is called in. His duty is to tell
what and why the patient ails. He may say that it is a simple
sickness, and prescribe accordingly. Or if he deems it really serious,
he declares it to be a case of witchcraft. He professes to be able to
ascertain who is ‘witching’ the sufferer; but as it is not his business
to mention names, he does not do so, neither do people inquire.
Having made thorough diagnosis, he shouts to the witch, who is
spoken of as Nximbi (x = sh), to let his patient alone, to let him live.
‘Does he not know that this wicked course will bring its deserts? If
he persists in destroying his victim the witch doctor will surely find
him out.’ Then all the people join in calling upon the unknown
Nximbi to relinquish his victim. The agony of mind of the sufferer,
and of those dear to him, can be imagined.
If in spite of all the man dies, in grief and rage the family call for
the witch doctor, Nganga-a-ngombo. Space prevents a detailed
description of his methods of procedure. He is a cunning rogue, and
has his agent, who ascertains whether any one is in special
disfavour, or whom it will be safe to declare a witch. He may decide
haphazard, or he may ascertain that the deceased man dreamed of
some one. He consults Nganga-a-moko. At early dawn the sound of
his ding-winti drum startles the town. Who knows whether he may
not be accused of the crime?
After working people into the wildest frenzy by a protracted
series of dances and mystery, the doctor at last selects one or two of
those present, and declares him or them to be guilty of the devilish
crime. The excitement culminates; the victim declares his innocence
and ignorance; but the rascally doctor tells a long story of the way in
which the crime was accomplished, till all feel the guilt fully
established, and would like to tear the witch to pieces on the spot.
However, there is a regular course of things, and a market-day is
appointed when the ordeal poison shall be taken. On the day
decided, all the people of the district assemble in vast crowds, as
they used to do in this country before executions were performed in
private.
The poor victim believes his innocence will be established, and
fearfully, but still generally willingly, he drinks the poisonous draught.
His stomach may reject the noxious compound. If he vomits, the
man is declared innocent, and the witch-doctor loses his fee—
indeed, in some parts is heavily fined for a false charge. More often,
if he has not avoided the risk by referring the death to some charm,
or to some person recently dead, he does his work too surely. His
victim staggers and falls. With a wild yell the bystanders rush at him
and beat him to death; shoot him, burn or bury him alive, throw him
over a precipice, or in some way finish the terrible work, with a
savage ferocity equal to their deep sense of the enormity of the
crime with which he is charged.
One could gather hundreds of terrible stories of the like kind
with much variety of detail; but the same principle runs through all.
We heard of a case where, on the Nganga making his declaration,
the witch-man went into his house close by, fetched his gun, and
shot the witch-doctor dead on the spot. He had to pay twenty slaves
to the friends of the Nganga; but no one ventured further to trouble
that witch.
Sometimes, and in some places, the witch-doctor is called in in
case of sickness only, and witches are killed to stay the sickness; and
again at the death of the person, sometimes even in the case of a
baby. A serious accident—as drowning, a fall from a palm-tree, or
the death of a chief—is considered the work of several witches; one
alone could not accomplish such a thing. Six men of the Vivi towns
were drowned through the upsetting of a canoe in the rapids, and
three witches were found for each man; eighteen victims had to
suffer for the death of those six men—twenty-four deaths in all.
Even when the victim vomits, and should be free, they
sometimes find an excuse to finish the work.
‘But why,’ you ask, ‘did you kill Mpanzu? What did he do to the
man who died? Did any one see him do it?’
‘Oh, Mundele! why do you ask such questions? Did not Nganga-
a-ngombo ascertain by his witch-charms? Did he not tell us how he
did it? And when he took the ordeal and swooned, was not his guilt
proved? Why, we should all say that any one who dared to question
such a decision must be himself a witch!’
‘But what does a witch do—how does he do it?’
‘How do I know? I am not a witch. Why, if we did not kill our
witches we should all die in no time! What would check them?’
You cannot get much further than this with young people or
common folk, all except the dictum of the Nganga ex cathedrâ.
Indeed, many of them have been accused, and have been fortunate
enough to reject the poison. Those who may escape by vomiting the
draught are generally confirmed in the truthfulness of the ordeal that
established their innocence.
However, I have never discussed the matter privately with an
intelligent native who did not acknowledge the wickedness and
deplore the custom. The fear of being dubbed a witch compels
generosity, and here lies the strength of the custom.
Nga Mbelenge, one of the chiefs of the district of Leopoldville,
Stanley Pool, has told me how it fared with him.
‘I had a town of my own when quite young. You know how the
Bayansi sell to the Bakongo, and we act as middlemen, and interpret
for them. I pushed business, and many traders came to me because
they had so much trouble with the other old chiefs about here. I
soon became very rich, married several wives, bought many slaves
out of my profits, and my town grew large.
‘The other old chiefs, instead of pushing their trade, grumbled
that I got so much. They would say, “Look at young Nga Mbelenge;
how rapidly he is growing rich! It seems only yesterday he was a
boy, and now to-day look at his town, see how rich he is! No doubt
he is selling souls also.” Without any warning or trial, they came
down on me suddenly, accused me of witchcraft, and in my own
town compelled me to drink the ordeal poison. I vomited, and thus
my innocence was established.’ He acknowledged that the whole
custom is very wicked. ‘But what am I to do? If I say that I will have
no more of it in my town, my people will say that I am myself a
witch, and therefore I do not wish further execution for witchcraft. If
I try to stop it, I bring it upon myself.’
As a sequel to this, I learned that a fortnight after, another man
was killed in his town as a witch.
The question is naturally asked, What is this crime of witchcraft?
Those people who do any trading imagine that a witch is able by
means of some fell sorcery to possess himself of the spirit of his
victim. He can then put the spirit into a tusk of ivory, or among his
merchandise, and convey it to the coast, where the white men will
buy it. In due course, if not at the time, the ‘witched’ man dies.
Then the white man can make him work for him in his country under
the sea. They believe that very many of the coast labourers are men
thus obtained, and often when they go to trade look anxiously about
for dead relatives. Sometimes when we are travelling they look on
with wonder and disgust as we open our tinned provisions,
‘calculating’ that that at least must be one of the uses to which we
put their dead relatives.
The notion of the land under the sea has its origin in their
faculty of observation. They see ships coming in from sea appear,
first the mast, then the hull; and thus at a decent distance out, so as
not to reveal the trick, we white men emerge from the ocean.
Travellers love to enlarge upon the wonders they have seen, and so
the story grows, and the people have been brought up in the belief
that away under the sea their relatives make cloth, etc., for us white
folk.
This is, however, a new idea, comparatively. The old notion still
prevails in many parts, that away in some dark forest land departed
spirits dwell. The witches, they think, have some interest in sending
away their fellows to the spirit land. Perhaps they get pay from the
spirits, no one knows or questions why. Who can know a witch’s
business but a witch?
Even if a man dies in war, or is taken by a wild beast or
crocodile, it is witchcraft. To such an extent is this believed, that
people will bathe in streams where crocodiles abound. So long as
there are plenty of people together, the cowardly reptiles are not
likely to attack. In this way the idea has come about that real
crocodiles will not eat men; but if such a thing occurs it is proof
positive that either a witch has transformed himself into a crocodile
to obtain his victim, or induced the reptile to do it for him. If you ask
how, ‘I do not know; I am not a witch.’ At Lukunga, Mr. Ingham, of
the Livingstone Mission, shot a huge crocodile which came out at
night after his pigs. In the stomach of the reptile were the anklets of
a woman, which were at once recognised by the townsfolk. Yet they
told me that the crocodile cannot have eaten the woman.
‘But how about those anklets?’
‘Very likely crocodiles have a fancy for such things. You see what
a lot of stones he had in his stomach. Perhaps he took off those
anklets when he had done as he was told to do.’
This was no ghastly joke. I discussed the matter further, and
asked a more intelligent companion whether he could really believe
as he asserted. He replied that the man was not joking.
A lad, who was for some time a scholar at our school at
Underhill Station, died in his own town a month or two after leaving
us. The people said that our Mr. Hughes had stolen the boy’s soul,
and sent it away to the white man’s land to be converted into
Krooboys to work for us.
The Ngombe people told us that once on the market near their
town, some travellers halted to buy palm wine, and all the people
heard a hoarse voice proceed from a tusk of ivory, ‘Give me a drink
of wine, I am fearfully thirsty.’ Some wine was poured into the tusk,
there was a sound of drinking, and after rest the travellers passed
on. Everyone believed the story, but I could never see any one who
was present. It was of course a spirit in transit to the coast.
Witch doctors are up to all manner of tricks in their wicked
business. Sometimes they declare that a dead man is the witch, and
will dig in the grave, and as they get near the corpse suddenly tell
the people to get out of the way. The doctor is going to shoot the
witch, then throwing down a little blood which he has secreted, he
fires a gun and points triumphantly to the blood of the escaped
witch.
One of our boys told us how he had helped to unmask one of
these tricks. His mother was ill, and the doctor said that there was a
witch in the ground under the head of the bed on which she slept.
The people all went out of the house; but the boy, who was anxious
to witness the destruction of the witch, begged to remain, and while
the doctor was busy digging, he found a bundle under the bed, and
took it out. It was the doctor’s charms, and among them he found
the gizzard of a fowl full of blood. He took it to the chief, who
examined it, and the doctor, discovering his loss, emerged to say
that the witch had been too sharp for him; he was obliged to run
away, the people were so angry with him for trying thus to deceive
them. It might seem too much to believe that, once discovered, he
would venture the same trick again; yet some time after he was sent
to inquire as to the death of a man in the town, and declared that
there were two witches, one he pointed out, the other was a dead
man. He proceeded to dig up the dead witch, and the chief,
remembering at once the old dodge of this very man, sent some one
to fetch his bundle, which he was more carefully watching. There
was another gizzard ready. This was too much for them. They seized
the wretched man, and, breaking his arms and legs, threw him over
the precipice, the fate intended for his victim.
There is a story which explains the cruelty of breaking the arms
and legs. A man had been accused of witchcraft, and thrown down
into the great chasm, a distance of over one hundred feet. He fell
into some soft mud at the bottom, and was able the next day to
return to the town. The people broke his arms and legs, to make
sure of him, and threw him down again; and such is the rule now.
Witch stories without end there are, but they still leave unsolved
the question, What is a witch? Some say a man who knows how to
weave the spell; others that an evil spirit takes up its abode in a
man to accomplish this; in either case, it is held to be an imperative
duty to kill the men. The spirit world is either under the sea or in a
dark forest land; but how the spirits live, and what they do, is not
known, since no one has ever returned to tell the story. But ghouls
and evil spirits are said to lurk about in the neighbourhood of graves
and uncanny places.
There is a natural fear of death—the spirit world is an unknown
land—but there is no apprehension of meeting Nzambi, nor is there
a burden of sin.
There is a sense of right and wrong. To steal, to lie, or to
commit other crimes is considered wrong, but only a wrong to those
who suffer thereby—there is no thought of God in it.
CHAPTER VI.

Cannibalism, Freemasonry and Charms.

C
annibalism is not met with on the Congo until we ascend almost
to Stanley Pool. The first tribe of the Bateke—the Alali—on the
north bank, are said to eat human flesh sometimes, but only
those who have been killed for witchcraft. The Amfuninga, or Amfunu,
the next tribe of Bateke, are also credited with the same vice. It is only
a report; we have no evidence of the fact. From Bolobo (2° South lat.)
upwards it is known to be a custom. White men have had to witness
the cutting up of victims, being powerless to prevent the act. When
remonstrated with, the natives have replied, ‘You kill your goats, and
no one finds fault with you; let us kill our meat then.’ When eating their
ghastly meal, the parents give morsels of the cooked flesh to the little
ones, to give them the taste for such food.

Why they eat human flesh it would be difficult to say. Tribes


towards the east coast eat their enemies that they may gain their
strength and courage, and it is probable that some such notion
underlies the custom on the Upper Congo. We hope to settle among
these folk soon, and may get to understand the reasons.
It is customary on the upper river to bury—sometimes alive—slaves
or wives of a deceased chief. This is done that he may not appear
without attendants in the spirit world.
‘The dark places of the earth are full of the habitations of cruelty.’
There are two customs which prevail through the country—
Ndembo, and another, very much like Freemasonry, called Nkimba.
In the practice of Ndembo, the initiating doctors get some one to
fall down in a pretended fit, and in this state he is carried away to an
enclosed place outside the town. This is called ‘dying Ndembo.’ Others
follow suit, generally boys and girls, but often young men and women.
Most feign the fit; but sometimes, when it has become the fashion,
others will be attacked with hysteria, and so the doctor gets sufficient
for a wholesale initiation, twenty or thirty, or even fifty.
They are supposed to have died. But the parents and friends supply
food, and after a period varying, according to custom, from three
months to three years, it is arranged that the doctor shall bring them to
life again. The custom is not only degrading, but extremely mischievous
in its results. So bad is it, that before we reached San Salvador the king
of Congo had stopped the custom in his town; and others had followed
suit in neighbouring districts, giving the reason that it was too vile to
be continued.
When the doctor’s fee had been paid, and money (goods) saved for
a feast, the Ndembo people are brought to life. At first they pretend to
know no one and nothing; they do not even know how to masticate
food, and friends have to perform that office for them. They want
everything nice that any one uninitiated may have, and beat them if it
is not granted, or even strangle and kill people. They do not get into
trouble for this, because it is thought that they do not know better.
Sometimes they carry on the pretence by talking gibberish, and
behaving as if they had returned from the spirit world. After this they
are known by another name, peculiar to those who have ‘died
Ndembo.’ There seems to be no advantage accruing to the initiated,
the license and the love of mystery seem to be the only inducements.
We hear of the custom far along on the upper river, as well as in the
cataract region.
The Nkimba custom is an introduction from the coast of
comparatively recent times. The initiatory fee is paid (about two dollars
of cloth and two fowls), and the novice repairs to an enclosure outside
of the town. He is given a drug which stupefies him, and when he
comes to himself he finds his fellow Nkimbas wearing a crinoline of
palm frondlets, their bodies whitened with pipeclay, and speaking a
mysterious language. Only males are initiated into this rite, which is
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like