0% found this document useful (0 votes)
16 views

Python Distilled 1st edition - eBook PDF pdf download

The document provides links to various Python eBooks available for download, including titles like 'Python Distilled' and 'Python For Dummies.' It also outlines the contents of the 'Python Distilled' book, which covers fundamental Python concepts, data manipulation, program structure, and object-oriented programming. Additionally, it includes information on purchasing options and copyright details.

Uploaded by

hubbsambarb4
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
0% found this document useful (0 votes)
16 views

Python Distilled 1st edition - eBook PDF pdf download

The document provides links to various Python eBooks available for download, including titles like 'Python Distilled' and 'Python For Dummies.' It also outlines the contents of the 'Python Distilled' book, which covers fundamental Python concepts, data manipulation, program structure, and object-oriented programming. Additionally, it includes information on purchasing options and copyright details.

Uploaded by

hubbsambarb4
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/ 57

Python Distilled 1st edition - eBook PDF install

download

https://ebookluna.com/download/python-distilled-ebook-pdf/

Download more ebook from https://ebookluna.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

(eBook PDF) Building Python Programs 1st Edition

https://ebookluna.com/product/ebook-pdf-building-python-programs-1st-
edition/

ebookluna.com

Python For Dummies 1st Edition - PDF Version

https://ebookluna.com/product/python-for-dummies-1st-edition-pdf-
version/

ebookluna.com

Problem Solving and Python Programming 1st edition - eBook


PDF

https://ebookluna.com/download/problem-solving-and-python-programming-
ebook-pdf/

ebookluna.com

Programming and Problem Solving with Python 1st Edition -


eBook PDF

https://ebookluna.com/download/programming-and-problem-solving-with-
python-ebook-pdf/

ebookluna.com
Data Structures & Algorithms in Python 1st Edition John
Canning - eBook PDF

https://ebookluna.com/download/data-structures-algorithms-in-python-
ebook-pdf-2/

ebookluna.com

Data Structures & Algorithms in Python 1st Edition John


Canning - eBook PDF

https://ebookluna.com/download/data-structures-algorithms-in-python-
ebook-pdf/

ebookluna.com

R and Python for Oceanographers: A Practical Guide with


Applications 1st Edition- eBook PDF

https://ebookluna.com/download/r-and-python-for-oceanographers-a-
practical-guide-with-applications-ebook-pdf/

ebookluna.com

(eBook PDF) Starting Out with Python (4th Edition)

https://ebookluna.com/product/ebook-pdf-starting-out-with-python-4th-
edition/

ebookluna.com

(eBook PDF) Python Programming in Context 3rd Edition

https://ebookluna.com/product/ebook-pdf-python-programming-in-
context-3rd-edition/

ebookluna.com
Python Distilled
This page intentionally left blank
Python Distilled

David M. Beazley

Boston • Columbus • New York • San Francisco • Amsterdam • Cape Town


Dubai • London • Madrid • Milan • Munich • Paris • Montreal • Toronto • Delhi • Mexico City
São Paulo • Sydney • Hong Kong • Seoul • Singapore • Taipei • Tokyo
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and the publisher was aware of a trademark
claim, the designations have been printed with initial capital letters or in all capitals.

The author and publisher have taken care in the preparation of this book, but make no expressed or
implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed
for incidental or consequential damages in connection with or arising out of the use of the information or
programs contained herein.

For information about buying this title in bulk quantities, or for special sales opportunities (which may
include electronic versions; custom cover designs; and content particular to your business, training goals,
marketing focus, or branding interests), please contact our corporate sales department
at corpsales@pearsoned.com or (800) 382-3419.

For government sales inquiries, please contact governmentsales@pearsoned.com.

For questions about sales outside the U.S., please contact intlcs@pearson.com.

Visit us on the Web: informit.com/aw

Library of Congress Control Number: 2021943288

Copyright © 2022 Pearson Education, Inc.

Cover illustration by EHStockphoto/Shutterstock

All rights reserved. This publication is protected by copyright, and permission must be obtained from the
publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or
by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding
permissions, request forms and the appropriate contacts within the Pearson Education Global Rights &
Permissions Department, please visit www.pearson.com/permissions.

ISBN-13: 978-0-13-417327-6
ISBN-10: 0-13-417327-9

ScoutAutomatedPrintCode
Contents

Preface xiii

1 Python Basics 1
1.1 Running Python 1
1.2 Python Programs 2
1.3 Primitives, Variables, and
Expressions 3
1.4 Arithmetic Operators 5
1.5 Conditionals and Control Flow 7
1.6 Text Strings 9
1.7 File Input and Output 12
1.8 Lists 13
1.9 Tuples 15
1.10 Sets 17
1.11 Dictionaries 18
1.12 Iteration and Looping 21
1.13 Functions 22
1.14 Exceptions 24
1.15 Program Termination 26
1.16 Objects and Classes 26
1.17 Modules 30
1.18 Script Writing 32
1.19 Packages 33
1.20 Structuring an Application 34
1.21 Managing Third-Party Packages 35
1.22 Python: It Fits Your Brain 36

2 Operators, Expressions, and Data


Manipulation 37
2.1 Literals 37
2.2 Expressions and Locations 38
2.3 Standard Operators 39
2.4 In-Place Assignment 41
2.5 Object Comparison 42
2.6 Ordered Comparison Operators 42
vi Contents

2.7 Boolean Expressions and Truth


Values 43
2.8 Conditional Expressions 44
2.9 Operations Involving Iterables 45
2.10 Operations on Sequences 47
2.11 Operations on Mutable
Sequences 49
2.12 Operations on Sets 50
2.13 Operations on Mappings 51
2.14 List, Set, and Dictionary
Comprehensions 52
2.15 Generator Expressions 54
2.16 The Attribute (.) Operator 56
2.17 The Function Call () Operator 56
2.18 Order of Evaluation 56
2.19 Final Words: The Secret Life of
Data 58

3 Program Structure and Control


Flow 59
3.1 Program Structure and
Execution 59
3.2 Conditional Execution 59
3.3 Loops and Iteration 60
3.4 Exceptions 64
3.4.1 The Exception
Hierarchy 67
3.4.2 Exceptions and Control
Flow 68
3.4.3 Defining New
Exceptions 69
3.4.4 Chained Exceptions 70
3.4.5 Exception
Tracebacks 73
3.4.6 Exception Handling
Advice 73
3.5 Context Managers and the with
Statement 75
3.6 Assertions and __debug__ 77
3.7 Final Words 78
Contents vii

4 Objects, Types, and Protocols 79


4.1 Essential Concepts 79
4.2 Object Identity and Type 80
4.3 Reference Counting and Garbage
Collection 81
4.4 References and Copies 83
4.5 Object Representation and Printing 84
4.6 First-Class Objects 85
4.7 Using None for Optional or Missing
Data 87
4.8 Object Protocols and Data
Abstraction 87
4.9 Object Protocol 89
4.10 Number Protocol 90
4.11 Comparison Protocol 92
4.12 Conversion Protocols 94
4.13 Container Protocol 95
4.14 Iteration Protocol 97
4.15 Attribute Protocol 98
4.16 Function Protocol 98
4.17 Context Manager Protocol 99
4.18 Final Words: On Being Pythonic 99

5 Functions 101
5.1 Function Definitions 101
5.2 Default Arguments 101
5.3 Variadic Arguments 102
5.4 Keyword Arguments 103
5.5 Variadic Keyword Arguments 104
5.6 Functions Accepting All Inputs 104
5.7 Positional-Only Arguments 105
5.8 Names, Documentation Strings, and Type
Hints 106
5.9 Function Application and Parameter
Passing 107
5.10 Return Values 109
5.11 Error Handling 110
5.12 Scoping Rules 111
5.13 Recursion 114
viii Contents

5.14 The lambda Expression 114


5.15 Higher-Order Functions 115
5.16 Argument Passing in Callback
Functions 118
5.17 Returning Results from
Callbacks 121
5.18 Decorators 124
5.19 Map, Filter, and Reduce 127
5.20 Function Introspection, Attributes,
and Signatures 129
5.21 Environment Inspection 131
5.22 Dynamic Code Execution and
Creation 133
5.23 Asynchronous Functions and
await 135
5.24 Final Words: Thoughts on Functions
and Composition 137

6 Generators 139
6.1 Generators and yield 139
6.2 Restartable Generators 142
6.3 Generator Delegation 142
6.4 Using Generators in Practice 144
6.5 Enhanced Generators and yield
Expressions 146
6.6 Applications of Enhanced
Generators 148
6.7 Generators and the Bridge to
Awaiting 151
6.8 Final Words: A Brief History of
Generators and Looking
Forward 152

7 Classes and Object-Oriented


Programming 153
7.1 Objects 153
7.2 The class Statement 154
7.3 Instances 155
7.4 Attribute Access 156
7.5 Scoping Rules 158
Contents ix

7.6 Operator Overloading and Protocols 159


7.7 Inheritance 160
7.8 Avoiding Inheritance via Composition 163
7.9 Avoiding Inheritance via Functions 166
7.10 Dynamic Binding and Duck Typing 167
7.11 The Danger of Inheriting from Built-in
Types 167
7.12 Class Variables and Methods 169
7.13 Static Methods 173
7.14 A Word about Design Patterns 176
7.15 Data Encapsulation and Private
Attributes 176
7.16 Type Hinting 179
7.17 Properties 180
7.18 Types, Interfaces, and Abstract Base
Classes 183
7.19 Multiple Inheritance, Interfaces, and
Mixins 187
7.20 Type-Based Dispatch 193
7.21 Class Decorators 194
7.22 Supervised Inheritance 197
7.23 The Object Life Cycle and Memory
Management 199
7.24 Weak References 204
7.25 Internal Object Representation and
Attribute Binding 206
7.26 Proxies, Wrappers, and Delegation 208
7.27 Reducing Memory Use with
__slots__ 210
7.28 Descriptors 211
7.29 Class Definition Process 215
7.30 Dynamic Class Creation 216
7.31 Metaclasses 217
7.32 Built-in Objects for Instances and
Classes 222
7.33 Final Words: Keep It Simple 223

8 Modules and Packages 225


8.1 Modules and the import Statement 225
x Contents

8.2 Module Caching 227


8.3 Importing Selected Names from a
Module 228
8.4 Circular Imports 230
8.5 Module Reloading and
Unloading 232
8.6 Module Compilation 233
8.7 The Module Search Path 234
8.8 Execution as the Main Program 234
8.9 Packages 235
8.10 Imports Within a Package 237
8.11 Running a Package Submodule as a
Script 238
8.12 Controlling the Package
Namespace 239
8.13 Controlling Package Exports 240
8.14 Package Data 241
8.15 Module Objects 242
8.16 Deploying Python Packages 243
8.17 The Penultimate Word: Start with a
Package 244
8.18 The Final Word: Keep It Simple 245

9 Input and Output 247


9.1 Data Representation 247
9.2 Text Encoding and Decoding 248
9.3 Text and Byte Formatting 250
9.4 Reading Command-Line
Options 254
9.5 Environment Variables 256
9.6 Files and File Objects 256
9.6.1 Filenames 257
9.6.2 File Modes 258
9.6.3 I/O Buffering 258
9.6.4 Text Mode Encoding 259
9.6.5 Text-Mode Line
Handling 260
9.7 I/O Abstraction Layers 260
9.7.1 File Methods 261
Contents xi

9.8 Standard Input, Output, and Error 263


9.9 Directories 264
9.10 The print() function 265
9.11 Generating Output 265
9.12 Consuming Input 266
9.13 Object Serialization 268
9.14 Blocking Operations and
Concurrency 269
9.14.1 Nonblocking I/O 270
9.14.2 I/O Polling 271
9.14.3 Threads 271
9.14.4 Concurrent Execution with
asyncio 272
9.15 Standard Library Modules 273
9.15.1 asyncio Module 273
9.15.2 binascii Module 274
9.15.3 cgi Module 275
9.15.4 configparser Module 276
9.15.5 csv Module 276
9.15.6 errno Module 277
9.15.7 fcntl Module 278
9.15.8 hashlib Module 278
9.15.9 http Package 279
9.15.10 io Module 279
9.15.11 json Module 280
9.15.12 logging Module 280
9.15.13 os Module 281
9.15.14 os.path Module 281
9.15.15 pathlib Module 282
9.15.16 re Module 283
9.15.17 shutil Module 284
9.15.18 select Module 284
9.15.19 smtplib Module 285
9.15.20 socket Module 286
9.15.21 struct Module 288
9.15.22 subprocess Module 288
9.15.23 tempfile Module 289
9.15.24 textwrap Module 290
xii Contents

9.15.25 threading Module 291


9.15.26 time Module 293
9.15.27 urllib Package 293
9.15.28 unicodedata
Module 294
9.15.29 xml Package 295
9.16 Final Words 296

10 Built-in Functions and Standard


Library 297
10.1 Built-in Functions 297
10.2 Built-in Exceptions 314
10.2.1 Exception Base
Classes 314
10.2.2 Exception Attributes 314
10.2.3 Predefined Exception
Classes 315
10.3 Standard Library 318
10.3.1 collections
Module 318
10.3.2 datetime Module 318
10.3.3 itertools Module 318
10.3.4 inspect Module 318
10.3.5 math Module 318
10.3.6 os Module 319
10.3.7 random Module 319
10.3.8 re Module 319
10.3.9 shutil Module 319
10.3.10 statistics
Module 319
10.3.11 sys Module 319
10.3.12 time Module 319
10.3.13 turtle Module 319
10.3.14 unittest Module 319
10.4 Final Words: Use the Built-Ins 320

Index 321
Preface

More than 20 years have passed since I authored the Python Essential Reference. At that time,
Python was a much smaller language and it came with a useful set of batteries in its
standard library. It was something that could mostly fit in your brain. The Essential Reference
reflected that era. It was a small book that you could take with you to write some Python
code on a desert island or inside a secret vault. Over the three subsequent revisions, the
Essential Reference stuck with this vision of being a compact but complete language
reference —because if you’re going to code in Python on vacation, why not use all of it?
Today, more than a decade since the publication of the last edition, the Python world is
much different. No longer a niche language, Python has become one of the most popular
programming languages in the world. Python programmers also have a wealth of
information at their fingertips in the form of advanced editors, IDEs, notebooks, web
pages, and more. In fact, there’s probably little need to consult a reference book when
almost any reference material you might want can be conjured to appear before your eyes
with the touch of a few keys.
If anything, the ease of information retrieval and the scale of the Python universe
presents a different kind of challenge. If you’re just starting to learn or need to solve a new
problem, it can be overwhelming to know where to begin. It can also be difficult to
separate the features of various tools from the core language itself. These kinds of problems
are the rationale for this book.
Python Distilled is a book about programming in Python. It’s not trying to document
everything that’s possible or has been done in Python. Its focus is on presenting a modern
yet curated (or distilled) core of the language. It has been informed by my years of teaching
Python to scientists, engineers, and software professionals. However, it’s also a product of
writing software libraries, pushing the edges of what makes Python tick, and finding out
what’s most useful.
For the most part, the book focuses on Python programming itself. This includes
abstraction techniques, program structure, data, functions, objects, modules, and so
forth— topics that will well serve programmers working on Python projects of any size.
Pure reference material that can be easily obtained via an IDE (such as lists of functions,
names of commands, arguments, etc.) is generally omitted. I’ve also made a conscious
choice to not describe the fast-changing world of Python tooling —editors, IDEs,
deployment, and related matters.
Perhaps controversially, I don’t generally focus on language features related to large-scale
software project management. Python is sometimes used for big and serious things—
comprised of millions upon millions of lines of code. Such applications require specialized
tooling, design, and features. They also involve committees, and meetings, and decisions
to be made about very important matters. All this is too much for this small book. But
xiv Preface

perhaps the honest answer is that I don’t use Python to write such applications— and
neither should you. At least not as a hobby.
In writing a book, there is always a cut-off for the ever-evolving language features. This
book was written during the era of Python 3.9. As such, it does not include some of the
major additions planned for later releases — for example, structural pattern matching.
That’s a topic for a different time and place.
Last, but not least, I think it’s important that programming remains fun. I hope that my
book will not only help you become a productive Python programmer but also capture
some of the magic that has inspired people to use Python for exploring the stars, flying
helicopters on Mars, and spraying squirrels with a water cannon in the backyard.

Acknowledgments
I’d like to thank the technical reviewers, Shawn Brown, Sophie Tabac, and Pete Fein, for
their helpful comments. I’d also like to thank my long-time editor Debra Williams Cauley
for her work on this and past projects. The many students who have taken my classes have
had a major if indirect impact on the topics covered in this book. Last, but not least, I’d
like to thank Paula, Thomas, and Lewis for their support and love.

About the Author


David Beazley is the author of the Python Essential Reference, Fourth Edition
(Addison-Wesley, 2010) and Python Cookbook, Third Edition (O’Reilly, 2013). He
currently teaches advanced computer science courses through his company Dabeaz LLC
( www.dabeaz.com ). He’s been using, writing, speaking, and teaching about Python
since 1996.
1
Python Basics

This chapter gives an overview of the core of the Python language. It covers variables,
data types, expressions, control flow, functions, classes, and input/output. The chapter
concludes with a discussion of modules, script writing, packages, and a few tips on
organizing larger programs. This chapter is not trying to provide comprehensive coverage
of every feature, nor does it concern itself with all of the tooling that might surround a
larger Python project. However, experienced programmers should be able to extrapolate
from the material here to write more advanced programs. Newcomers are encouraged to
try the examples in a simple environment, such as a terminal window and a basic text
editor.

1.1 Running Python


Python programs are executed by an interpreter. There are many different environments
in which the Python interpreter might run —an IDE, a browser, or a terminal window.
However, underneath all that, the core of the interpreter is a text-based application that
can be started by typing python in a command shell such as bash. Since Python 2 and
Python 3 might both be installed on the same machine, you might need to type python2
or python3 to pick a version. This book assumes Python 3.8 or newer.
When the interpreter starts, a prompt appears where you can type programs into a
so-called “read-evaluation-print loop” (or REPL). For example, in the following output,
the interpreter displays its copyright message and presents the user with the >>> prompt, at
which the user types a familiar “Hello World” program:

Python 3.8.0 (default, Feb 3 2019, 05:53:21)


[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Hello World')
Hello World
>>>
2 Chapter 1 Python Basics

Certain environments may display a different prompt. The following output is from
ipython (an alternate shell for Python):

Python 3.8.0 (default, Feb 4, 2019, 07:39:16)


Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: print('Hello World')


Hello World

In [2]:

Regardless of the exact form of output you see, the underlying principle is the same.
You type a command, it runs, and you immediately see the output.
Python’s interactive mode is one of its most useful features because you can type any
valid statement and immediately see the result. This is useful for debugging and
experimentation. Many people, including the author, use interactive Python as their
desktop calculator. For example:
>>> 6000 + 4523.50 + 134.25
10657.75
>>> _ + 8192.75
18850.5
>>>

When you use Python interactively, the variable _ holds the result of the last operation.
This is useful if you want to use that result in subsequent statements. This variable only
gets defined when working interactively, so don’t use it in saved programs.
You can exit the interactive interpreter by typing quit() or the EOF (end of file)
character. On UNIX, EOF is Ctrl+D; on Windows, it’s Ctrl+Z.

1.2 Python Programs


If you want to create a program that you can run repeatedly, put statements in a text file.
For example:
# hello.py
print('Hello World')

Python source files are UTF-8-encoded text files that normally have a .py suffix. The
# character denotes a comment that extends to the end of the line. International (Unicode)
characters can be freely used in the source code as long as you use the UTF-8 encoding
(this is the default in most editors, but it never hurts to check your editor settings if you’re
unsure).
1.3 Primitives, Variables, and Expressions 3

To execute the hello.py file, provide the filename to the interpreter as follows:
shell % python3 hello.py
Hello World
shell %

It is common to use #! to specify the interpreter on the first line of a program, like this:
#!/usr/bin/env python3
print('Hello World')

On UNIX, if you give this file execute permissions (for example, by chmod +x
hello.py), you can run the program by typing hello.py into your shell.
On Windows, you can double-click on a .py file or type the name of the program into
the Run command on the Windows Start menu to launch it. The #! line, if given, is used
to pick the interpreter version (Python 2 versus 3). Execution of a program might take
place in a console window that disappears immediately after the program completes—
often before you can read its output. For debugging, it’s better to run the program within
a Python development environment.
The interpreter runs statements in order until it reaches the end of the input file. At
that point, the program terminates and Python exits.

1.3 Primitives, Variables, and Expressions


Python provides a collection of primitive types such as integers, floats, and strings:
42 # int
4.2 # float
'forty-two' # str
True # bool

A variable is a name that refers to a value. A value represents an object of some type:
x = 42

Sometimes you might see a type explicitly attached to a name. For example:
x: int = 42

The type is merely a hint to improve code readability. It can be used by third-party
code-checking tools. Otherwise, it is completely ignored. It does not prevent you from
assigning a different kind of value later.
An expression is a combination of primitives, names, and operators that produces a
value:
2 + 3 * 4 # -> 14
4 Chapter 1 Python Basics

The following program uses variables and expressions to perform a compound-interest


calculation:
# interest.py

principal = 1000 # Initial amount


rate = 0.05 # Interest rate
numyears = 5 # Number of years
year = 1
while year <= numyears:
principal = principal * (1 + rate)
print(year, principal)
year += 1

When executed, it produces the following output:


1 1050.0
2 1102.5
3 1157.625
4 1215.5062500000001
5 1276.2815625000003

The while statement tests the conditional expression that immediately follows. If the
tested condition is true, the body of the while statement executes. The condition is
then retested and the body executed again until the condition becomes false. The body
of the loop is denoted by indentation. Thus, the three statements following while in
interest.py execute on each iteration. Python doesn’t specify the amount of required
indentation, as long as it’s consistent within a block. It is most common to use four spaces
per indentation level.
One problem with the interest.py program is that the output isn’t very pretty. To
make it better, you could right-align the columns and limit the precision of principal
to two digits. Change the print() function to use a so-called f-string like this:
print(f'{year:>3d} {principal:0.2f}')

In the f-string, variable names and expressions can be evaluated by enclosing them in
curly braces. Optionally, each substitution can have a formatting specifier attached to it.
'>3d' means a three-digit decimal number, right aligned. '0.2f' means a floating-point
number with two decimal places of accuracy. More information about these formatting
codes can be found in Chapter 9.
Now the output of the program looks like this:
1 1050.00
2 1102.50
3 1157.62
4 1215.51
5 1276.28
1.4 Arithmetic Operators 5

1.4 Arithmetic Operators


Python has a standard set of mathematical operators, shown in Table 1.1. These operators
have the same meaning they do in most other programming languages.

Table 1.1 Arithmetic Operators

Operation Description

x + y Addition
x - y Subtraction
x * y Multiplication
x / y Division
x // y Truncating division
x ** y Power (x to the y power)
x % y Modulo (x mod y). Remainder.
–x Unary minus
+x Unary plus

The division operator (/) produces a floating-point number when applied to integers.
Therefore, 7/4 is 1.75. The truncating division operator //, also known as floor division,
truncates the result to an integer and works with both integers and floating-point
numbers. The modulo operator returns the remainder of the division x // y. For
example, 7 % 4 is 3. For floating-point numbers, the modulo operator returns the
floating-point remainder of x // y, which is x – (x // y) * y.
In addition, the built-in functions in Table 1.2 provide a few more commonly used
numerical operations.

Table 1.2 Common Mathematic Functions


Function Description

abs(x) Absolute value


divmod(x,y) Returns (x // y, x % y)
pow(x,y [,modulo]) Returns (x ** y) % modulo
round(x,[n]) Rounds to the nearest multiple of 10 to the nth power.

The round() function implements “banker’s rounding.” If the value being rounded is
equally close to two multiples, it is rounded to the nearest even multiple (for example, 0.5
is rounded to 0.0, and 1.5 is rounded to 2.0).
Integers provide a few additional operators to support bit manipulation, shown in
Table 1.3.
6 Chapter 1 Python Basics

Table 1.3 Bit Manipulation Operators

Operation Description

x << y Left shift


x >> y Right shift
x & y Bitwise and
x | y Bitwise or
x ^ y Bitwise xor (exclusive or)
~x Bitwise negation

One would commonly use these with binary integers. For example:
a = 0b11001001
mask = 0b11110000
x = (a & mask) >> 4 # x = 0b1100 (12)

In this example, 0b11001001 is how you write an integer value in binary. You could
have written it as decimal 201 or hexadecimal 0xc9, but if you’re fiddling with bits, binary
makes it easier to visualize what you’re doing.
The semantics of the bitwise operators assumes that the integers use a two’s
complement binary representation and that the sign bit is infinitely extended to the left.
Some care is required if you are working with raw bit patterns that are intended to map to
native integers on the hardware. This is because Python does not truncate the bits or allow
values to overflow — instead, the result will grow arbitrarily large in magnitude. It’s up to
you to make sure the result is properly sized or truncated if needed.
To compare numbers, use the comparison operators in Table 1.4.

Table 1.4 Comparison Operators

Operation Description

x == y Equal to
x != y Not equal to
x < y Less than
x > y Greater than
x >= y Greater than or equal to
x <= y Less than or equal to

The result of a comparison is a Boolean value True or False.


The and, or, and not operators (not to be confused with the bit-manipulation
operators above) can form more complex Boolean expressions. The behavior of these
operators is as shown in Table 1.5.
A value is considered false if it is literally False, None, numerically zero, or empty.
Otherwise, it’s considered true.
1.5 Conditionals and Control Flow 7

Table 1.5 Logical Operators

Operator Description

x or y If x is false, return y; otherwise, return x.


x and y If x is false, return x; otherwise, return y.
not x If x is false, return True; otherwise, return False.

It is common to write an expression that updates a value. For example:


x = x + 1
y = y * n

For these, you can write the following shortened operation instead:
x += 1
y *= n

This shortened form of update can be used with any of the +, -, *, **, /, //, %, &, |, ^,
<<, >>operators. Python does not have increment (++) or decrement (--) operators found
in some other languages.

1.5 Conditionals and Control Flow


The while, if and else statements are used for looping and conditional code execution.
Here’s an example:
if a < b:
print('Computer says Yes')
else:
print('Computer says No')

The bodies of the if and else clauses are denoted by indentation. The else clause is
optional. To create an empty clause, use the pass statement, as follows:
if a < b:
pass # Do nothing
else:
print('Computer says No')

To handle multiple-test cases, use the elif statement:


if suffix == '.htm':
content = 'text/html'
elif suffix == '.jpg':
content = 'image/jpeg'
8 Chapter 1 Python Basics

elif suffix == '.png':


content = 'image/png'
else:
raise RuntimeError(f'Unknown content type {suffix!r}')

If you are assigning a value in combination with a test, use a conditional expression:
maxval = a if a > b else b

This is the same as the longer:


if a > b:
maxval = a
else:
maxval = b

Sometimes, you may see the assignment of a variable and a conditional combined
together using the := operator. This is known as an assignment expression (or more
colloquially as the “walrus operator” because := looks like a walrus tipped over on its
side —presumably playing dead). For example:
x = 0
while (x := x + 1) < 10: # Prints 1, 2, 3, ..., 9
print(x)

The parentheses used to surround an assignment expression are always required.


The break statement can be used to abort a loop early. It only applies to the innermost
loop. For example:
x = 0
while x < 10:
if x == 5:
break # Stops the loop. Moves to Done below
print(x)
x += 1

print('Done')

The continue statement skips the rest of the loop body and goes back to the top of the
loop. For example:
x = 0
while x < 10:
x += 1
if x == 5:
continue # Skips the print(x). Goes back to loop start.
print(x)

print('Done')
1.6 Text Strings 9

1.6 Text Strings


To define a string literal, enclose it in single, double, or triple quotes as follows:

a = 'Hello World'
b = "Python is groovy"
c = '''Computer says no.'''
d = """Computer still says no."""

The same type of quote used to start a string must be used to terminate it. Triple-
quoted strings capture all the text until the terminating triple quote — as opposed to single-
and double-quoted strings which must be specified on one logical line. Triple-quoted
strings are useful when the contents of a string literal span multiple lines of text:
print('''Content-type: text/html

<h1> Hello World </h1>


Click <a href="http://www.python.org">here</a>.
''')

Immediately adjacent string literals are concatenated into a single string. Thus, the
above example could also be written as:
print(
'Content-type: text/html\n'
'\n'
'<h1> Hello World </h1>\n'
'Clock <a href="http://www.python.org">here</a>\n'
)

If the opening quotation mark of a string is prefaced by an f, escaped expressions


within a string are evaluated. For example, in earlier examples, the following statement was
used to output values of a calculation:
print(f'{year:>3d} {principal:0.2f}')

Although this is only using simple variable names, any valid expression can appear. For
example:
base_year = 2020
...
print(f'{base_year + year:>4d} {principal:0.2f}')

As an alternative to f-strings, the format() method and % operator are also sometimes
used to format strings. For example:
print('{0:>3d} {1:0.2f}'.format(year, principal))
print('%3d %0.2f' % (year, principal))
10 Chapter 1 Python Basics

More information about string formatting is found in Chapter 9.


Strings are stored as sequences of Unicode characters indexed by integers, starting at
zero. Negative indices index from the end of the string. The length of a string s is
computed using len(s). To extract a single character, use the indexing operator s[i]
where i is the index.
a = 'Hello World'
print(len(a)) # 11
b = a[4] # b = 'o'
c = a[-1] # c = 'd'

To extract a substring, use the slicing operator s[i:j]. It extracts all characters from s
whose index k is in the range i <= k < j. If either index is omitted, the beginning or end
of the string is assumed, respectively:
c = a[:5] # c = 'Hello'
d = a[6:] # d = 'World'
e = a[3:8] # e = 'lo Wo'
f = a[-5:] # f = 'World'

Strings have a variety of methods for manipulating their contents. For example, the
replace() method performs a simple text replacement:
g = a.replace('Hello', 'Hello Cruel') # f = 'Hello Cruel World'

Table 1.6 shows a few common string methods. Here and elsewhere, arguments
enclosed in square brackets are optional.

Table 1.6 Common String Methods

Method Description

s.endswith(prefix [,start [,end]]) Checks whether a string ends with prefix.


s.find(sub [, start [,end]]) Finds the first occurrence of the specified
substring sub or -1 if not found.
s.lower() Converts to lowercase.
s.replace(old, new [,maxreplace]) Replaces a substring.
s.split([sep [,maxsplit]]) Splits a string using sep as a delimiter.
maxsplit is the maximum number of splits to
perform.
s.startswith(prefix [,start [,end]]) Checks whether a string starts with prefix.
s.strip([chrs]) Removes leading and trailing whitespace or
characters supplied in chrs.
s.upper() Converts a string to uppercase.

Strings are concatenated with the plus (+) operator:


g = a + 'ly' # g = 'Hello Worldly'
Other documents randomly have
different content
CHAPTER XLIX.
A PAINFUL INTERVIEW.

We must now go back a few hours—only to the morning of this


eventful day—in order to describe the interview which Mr. Clarence
Villiers had with his respectable aunt Mrs. Slingsby, at her residence
in Old Burlington Street.
He called at her abode as early as nine o'clock,—for he had passed a
sleepless night, in consequence of the communication made to him
by the individual whom he as yet knew only as Captain Sparks, and
of whose arrest on the preceding night he was as yet ignorant.
Mrs. Slingsby, Adelais, and Rosamond were seated at breakfast in a
comfortable little parlour, when Clarence was announced.
At first his appearance at so unusual an hour and when he was
supposed to be on his way to his office in Somerset House, excited
some alarm, lest he had bad news to communicate; and the sisters
already trembled for fear their father had discovered their abode.
But he speedily reassured them by declaring that he intended to give
himself a holiday that morning, and had therefore come to join them
at the breakfast-table.
"You are welcome, Clarence," said Mrs. Slingsby, while Adelais
appeared so pleased at this unexpected visit that the enhanced
carnation tinge of her cheeks and the joy that flashed in her fine
eyes rendered her transcendently beautiful.
But Rosamond seemed pensive and even melancholy—although she
endeavoured to smile and appear gay.
"I had a visit from Captain Sparks last evening," observed Clarence.
"He is going to America, and he called to take leave of me, as well
as to entrust me with some little commission, which I of course
undertook."
"And we heard a most wholesome and beneficial discourse from the
Reverend Mr. Sawkins," observed Mrs. Slingsby.
"Was Mr. Sheepshanks present?" inquired Villiers, without looking at
his aunt, and apparently intent only on carving the ham.
"My dear Clarence," said Mrs. Slingsby in a serious, reproachful tone,
"your question is light and inconsiderate. You doubtless intended it
as a jest, but the object to which it refers is one painfully calculated
to wound those who have the good cause at heart. Mr. Sheepshanks
has conducted himself in a manner that has produced the most lively
grief as well as the greatest astonishment in what may be strictly
termed the religious world. Sir Henry Courtenay was shocked when I
narrated the incident to him."
"Oh! Sir Henry was shocked, was he?" exclaimed Clarence. "Well, for
my part, I should have conceived that a man of fashion would have
cared very little for all the Sheepshanks' and Sawkins' in the
universe."
"Clarence!" said Mrs. Slingsby, "what is the matter with you this
morning? There seems to be an unusual flippancy in your
observations——"
"Not at all, my dear aunt. Only, I conceive that a man who is fond of
gaiety—who goes to parties—mixes with the élite of the West End,
and so on, can have but little time to devote to the interests of
Cannibal-Clothing Associations."
"My dear nephew, you astonish me!" exclaimed Mrs. Slingsby. "Is it
to affix a vulgar nick-name to an admirable institution, that you call
it a Cannibal-Clothing Association? I once thought you had some
degree of respect for the philanthropic and religious establishments
which are the boast and ornament of your native land. But——"
"My dear aunt, pardon me if I have offended you," said Clarence—
but in a cool and indifferent tone. "I really forgot at the moment the
name of the institution to which that arrant hypocrite and scoundrel
Sheepshanks belonged."
"Use not such harsh words, Clarence," enjoined Mrs. Slingsby, who
knew not what to think of her nephew's unusual manner and
discourse. "Mr. Sheepshanks has lost himself in the estimation of all
persons of rightly constituted minds; but the Christian spirit of
forgiveness commands us to be lenient in our comments on the
actions even of the wicked."
"That may be," said Clarence. "But as I read the account in the
newspapers, it certainly looked so black against this Sheepshanks,
that had he been sent to Newgate, he would have had no more than
his due. Now, my opinion is this:—robbery is always a heinous
crime; but he who robs his fellow-creatures under the cloak of
religion, is an atrocious sinner indeed. Hypocrisy, my dear aunt, is a
detestable vice; and you, as a woman of sound sense and discerning
judgment, must admit the truth of my observation. But we were
talking of Sir Henry Courtenay."
"You must not utter a word against him," said Adelais, in the most
artless manner possible; "for Rosamond has conceived so high an
opinion of him——"
"Because dear Mrs. Slingsby has represented his virtues—his mental
qualifications—his admirable character to me in terms which make
me as enthusiastic as herself in extolling so good and amiable a
man," exclaimed Rosamond, speaking with an ardour which was the
more striking, because the natural purity of her soul prevented her
from seeing the necessity of checking it.
Mrs. Slingsby coloured and glanced uneasily towards her nephew,
who did not, however, appear to notice that the conversation had
taken a turn which was disagreeable to her.
In fact, the suspicions originally excited in his mind by the
communications of the preceding evening, were now materially
strengthened; and the more he contemplated the character of his
aunt, the more transparent became the film that had so long blinded
him as to its real nature.
"And so you are a great admirer of Sir Henry Courtenay,
Rosamond?" he said, endeavouring to maintain as calm and placid
an exterior as possible.
"Rosamond is fully aware that virtue deserves respect, wherever it
exists," returned Mrs. Slingsby hastily.
"And Sir Henry Courtenay is the pattern of all virtue, dear madam—
is he not?" exclaimed Rosamond.
"He is a very good man, my dear, as I have frequently assured you,"
said the pious widow. "But let us change a conversation which does
not appear agreeable to Clarence?"
"I would not for the world manifest so much selfishness," observed
Villiers, coolly, "as to quit a topic which gives so much gratification to
Rosamond. At the same time—as the future husband of Adelais, and
therefore soon to be your brother-in-law, dear Rosamond—I must
warn you against conceiving extravagant notions of the integrity and
immaculate virtue of any man who belongs to what is called the
Fashionable World."
"But dear Mrs. Slingsby has assured me, Clarence," ejaculated
Rosamond, warmly, "that Sir Henry Courtenay is an exception to the
general rule—that he is the very pattern of every thing generous and
good—and that no one could err in following his advice, whatever it
might be. Oh! I can assure you——"
Rosamond stopped short; for Mrs. Slingsby, seeing that her
nephew's countenance was becoming purple with indignation as the
artless girl thus gave vent to the enthusiasm excited in her soul by
the most insidious representations,—Mrs. Slingsby, we say, had
touched her with her foot beneath the table—a movement naturally
construed by Rosamond into a hint to cut short her observations.
"You can retire, dear girls," said Mrs. Slingsby. "I wish to have a little
conversation with Clarence."
"Do not keep us away long, dear madam," exclaimed Adelais, in a
playful manner, as she rose to quit the room with her sister.
Clarence and Mrs. Slingsby were now alone together; and the
position of each was a most painful one.
The aunt saw that something was wrong; and her guilty conscience
excited a thousand vague fears within her bosom; while the nephew
felt convinced that the relative, whom he had hitherto loved and
respected, was worthy only of his abhorrence and contempt.
There was a long pause in the conversation after the sisters had left
the room; but at length the silence, so irksome to both nephew and
aunt, was broken by the latter.
"Clarence—something appears to have vexed—to have annoyed you
this morning," she observed, in a tremulous tone.
"Do you know," he said, turning abruptly round towards her, and
fixing a searching glance upon her countenance, "that you act most
unwisely—most indiscreetly—nay, most incorrectly, to expatiate so
much upon the virtues of Sir Henry Courtenay? When I first entered
the room this morning, I found Rosamond pensive and thoughtful;
and she said not a word until that man's name was mentioned,
when she became as it were enthusiastic in his defence, although no
actual attack was made by me upon his character. What is the
meaning of this strange conduct?"
"Clarence—if, in my respect for Sir Henry Courtenay—I have been
too warm in my praises of his character,—if——"
"Aunt, there is no supposition in the case," interrupted Villiers,
almost sternly. "You have been too warm—and heaven only knows
with what object! God forbid that I should impute the worst motives
to your conduct in this respect: but a dreadful suspicion has been
excited in my mind——"
"A suspicion!" murmured Mrs. Slingsby faintly, while the glance
which she threw upon her nephew was full of uneasiness.
"Yes—a suspicion!" he repeated; "and most painful—oh! most painful
is it to me to be compelled to address you in this manner. But the
case is too serious to allow me to remain silent. In one word, have
you not made an impression on the mind of that artless girl which
may endanger her peace?—have you not been encouraging in her
breast an admiration for a man old enough to be her grandfather—
an admiration which is not natural, and which is calculated to inspire
her with feelings towards a sexagenarian dandy——"
"Clarence!" exclaimed the pious lady, in a hysterical manner; "how
dare you address me in this dictatorial tone? Would you seek to
invest my conduct in bestowing well-merited praise on a good man,
with an aspect so black——"
"Your indignation is well feigned!" cried Villiers, his lips quivering
with rage. "But the day of deception has passed—hypocrisy shall no
longer impose upon me. If I accuse you unjustly, I will grovel as an
abject wretch at your feet to manifest my contrition. Before I thus
debase myself, however, you must prove to me that you are indeed
the noble-minded—the open-hearted—the immaculate woman I
have so long loved and revered! Tell me, then, the real—the true
history of that night when a boy was received into this house
through charity—a few years ago——"
Mrs. Slingsby became as pale as death, and sate gazing with
haggard eyes upon her nephew—unable to avert her glance, and yet
shrinking from his.
"Then you are guilty, madam," he said, after a few moments' pause;
"and the excellent—the virtuous—the upright Sir Henry Courtenay is
your lover! My God! did the world ever know hypocrisy so
abominable—so black as this?"
These words were uttered with extreme bitterness—and Mrs.
Slingsby burst into a flood of tears, while she covered her face with
her hands.
Clarence possessed a generous heart; and this sight moved him.
"My dear aunt," he said, "I do not wish to mortify you—much less to
humiliate you in my presence. In your own estimation you must
necessarily be humiliated enough. Neither will I dwell at any length
upon the pain—the intense grief which I experience in finding you so
different from what I have ever believed you to be—until now!" he
added, in a mournful tone. "Were you my sister, or did you stand
with reference to me in a degree of relationship that would permit
me to remonstrate and advise, I should perhaps both reproach and
counsel you. But it would ill become a nephew to address his aunt in
such a manner."
"Clarence, will you expose me? will you ruin me?" demanded Mrs.
Slingsby, in a hysterical tone.
"Not for worlds would I injure you!" ejaculated the young man. "But
I must receive no more favours at your hands! Here—take back the
money which you gave me a few days ago. Thank God! I have not
yet expended any of it—and the arrangements I had made to furnish
a house for the reception of my Adelais, can be countermanded. She
will not object to share a lodging with me—until, by my own honest
exertions," he added proudly, "I may be able to give her a suitable
home."
And, as he spoke, he cast a roll of Bank-notes upon the table.
"Oh! Clarence—if I have been weak—frail—culpable," cried the
widow, "you are at least severe and cruel; for I have ever done all I
could to serve your interests."
"Were I to express my real opinion on that head," answered Villiers,
"I might grieve you still more than I have already done. A bandage
has fallen from my eyes—and I can now understand how necessary
an instrument of publicity I have been for your assumed virtues. But,
in the name of God! let us argue the point no further; for sincerely—
sincerely do I assert my unwillingness to give you additional pain.
Pardon me, however, if I declare how impossible it is—how
inconsistent it would be—to leave those innocent girls in a dwelling
which is visited by such a man as that Sir Henry Courtenay."
"How could you remove them elsewhere, without exposing me,
Clarence?" demanded his aunt in an imploring tone. "What
explanation can you or I give them, to account in a reasonable
manner for the suddenness of such a step?"
Villiers paced the room in an agitated manner.
He knew not how to act.
To leave Adelais and Rosamond in the society of his aunt was
repugnant to his high sense of honour and his correct notions of
propriety; and whither to remove them he knew not.
He had seen and heard enough at the breakfast-table, to convince
him that Mrs. Slingsby had some sinister motive in creating in the
mind of Rosamond,—that innocent, artless mind, which was so
susceptible of any impressions which a designing woman might
choose to make upon it,—a feeling of admiration in favour of the
baronet; and although he had to a considerable extent curbed the
resentment and the indignation which his aunt's conduct in this
respect had aroused within him, still to leave that young maiden any
longer within an atmosphere of infection, was impossible! No: he
would sooner restore the sisters to their father, and leave to
circumstances the realization of his hopes in regard to Adelais!
While he was still deliberating within himself what course to pursue,
and while Mrs. Slingsby was anxiously watching him as he paced the
room with agitated steps, the servant entered with the morning's
newspaper.
Clarence took it from the table in a mechanical manner and glanced
his eye over the first page: but his thoughts were too painfully pre-
occupied to permit him to entertain, even for an instant, any idea of
reading the journal.
No:—it was one of those unwitting actions which we often perform
when sorely embarrassed or bewildered,—an action without positive
motive and without aim.
But how often do the most trivial deeds exercise a paramount
influence over our destinies!
And this simple action of glancing at the newspaper proved to be an
instance of the kind.
For at the moment when Clarence was about to throw the journal
back again upon the table and resume his agitated walk, his eyes
encountered an advertisement which instantaneously arrested his
attention.
Then, with beating heart and with an expression of joy rapidly
spreading itself over his countenance, he read the following lines:—
"To A. and R.—Your distressed and almost heart-broken father
implores you to return to him. The past shall be forgotten on his
side; and no obstacle shall be opposed to the happiness of A.
Your father is lying on a sick bed, and again implores that this
prayer may not be made in vain."
"God be thanked!" cried Villiers, no longer able to restrain his joy;
and handing the newspaper to his aunt, he directed her attention to
the advertisement.
"Here is an apology at once for the removal of the young ladies from
this house, Clarence," observed Mrs. Slingsby. "And now that you are
saved from the embarrassment in which you were plunged but a few
minutes back, will you promise never—never to reveal—and, if
possible, to forget——"
"You allude to your conduct towards Rosamond?" said Villiers. "Tell
me its motive—and I swear solemnly——"
"In one word, then," interrupted his aunt, "let Rosamond beware of
Sir Henry Courtenay! And now answer me a single question—for I
see you are impatient to be gone:—How came you to discover——
what meant your allusion—to—to the boy who was received into this
house——"
"I cannot stay to explain all that," cried Villiers. "But rest assured
that your character stands no chance of being made the subject of
scandalous talk—unless, indeed, your future actions——"
"Enough, Clarence!" exclaimed Mrs. Slingsby. "I know that you must
despise me: but spare me any farther humiliation!"
She then rang the bell, and desired the servant to summon Adelais
and Rosamond.
We need not pause to describe the joy which those fair beings
experienced when Clarence showed them the advertisement inviting
them to return home; although tears immediately afterwards started
into their eyes, when they read that their father was upon a bed of
sickness.
They once more retired to their bed-chamber to prepare their
toilette for departure; and, when a hackney-coach drove round to
the door, they took leave of Mrs. Slingsby with demonstrations of
gratitude which struck to her heart like a remorse.
Clarence accompanied them back to the cottage; and his heart
palpitated violently—he scarcely knew wherefore—when he assisted
them to alight.
The front door was opened by the female servant, who uttered a cry
of joy on beholding the young ladies once more; and with trembling
steps Adelais and Rosamond entered the parlour, followed by
Clarence.
To their surprise—and, at first, to their great delight—the sisters
found themselves, on crossing the threshold of the room, in the
presence of their father, who was looking pale, it was true—but with
concentrated anger, and not with illness.
Adelais and Rosamond fell on their knees before him, exclaiming,
"Forgive us, dear father—forgive us!"
"How am I to receive you, Adelais?" he asked in a cold voice: "as
Miss Torrens—or as——"
"As Miss Torrens at present, sir," answered Clarence stepping
forward, and speaking in a firm though respectful tone. "But, in
accordance with the promise held out in that advertisement which
appears in to-day's journal, I hope that your elder daughter will soon
be mine—and with your permission and blessing also."
"Where have my daughters been residing during their absence, sir?"
inquired Mr. Torrens, without appearing to notice the latter portion of
Villiers' observations.
"Under the protection of a female relative of mine, sir," answered
Clarence, with increasing misgivings at the cold demeanour of the
father of his beloved.
"Thank you for the information, sir," said Mr. Torrens, with a smile of
triumph. "At least you have so far disarmed my resentment, that you
have brought me back my daughter pure and innocent as when you
enticed her away, with the aid of a villanous robber."
"A robber!" ejaculated Clarence indignantly.
"Yes, sir," continued Mr. Torrens, in a sneering tone; "your worthy
colleague, Captain Sparks, is a common highwayman—a thief—
properly named Thomas Rainford; and at this moment he is a
prisoner in Horsemonger Lane Gaol. Scarcely ten minutes have
elapsed since I received a note from Mr. Howard, a solicitor,
informing me of the fact."
Clarence was so astounded by this announcement, that for a few
moments he could make no reply; and the young ladies, who had in
the meantime slowly risen from their suppliant posture and were
now standing timidly by their father's side, exchanged glances of
painful surprise.
"Yes," resumed Mr. Torrens in a stern and severe tone, "that man,
who aided you to effect the abduction of these disobedient girls, is a
common highwayman—and you could not be ignorant of that fact!"
"As I live, sir," ejaculated Clarence, at length recovering the power of
speech. "I was ignorant of the fact; and even now——But," he
added, correcting himself, "I cannot doubt your word! At the same
time, permit me to assure you that I had never seen him until that
night——"
"I require no farther explanation, sir," interrupted Mr. Torrens. "My
daughters are now once more under the paternal roof—inveigled
back again, it is true, by a stratagem on my part——"
"A stratagem!" repeated Clarence, while Adelais uttered a faint
shriek, and sank weeping into her sister's arms.
"Yes—a stratagem, sir!" ejaculated Mr. Torrens. "And now learn my
decision, Mr. Villiers! Sooner than she shall become your wife," he
continued, pointing towards the unhappy girl, "I would give her to
the meanest hind who toils for his daily bread. Depart, sir:—this
house is at least a place where my authority can alone prevail!"
"Mr. Torrens—I beseech—I implore you——" began the wretched
young man, whose hopes were thus suddenly menaced so cruelly.
"Depart, sir!" thundered the angry father; "or I shall use violence—
and we will then see whether you will strike in return the parent of
her whom you affect to love!"
And he advanced towards Villiers in a menacing manner.
"I will not stay to irritate you, sir," said Clarence, feeling as if his
heart were ready to burst. "Adelais—remember one who will never
cease to remember you! Rosamond, farewell!"
Mr. Torrens became more and more impatient; and Villiers quitted
the house with feelings as different from those which had animated
him when he entered it, as the deepest despair is different from the
most joyous hope.
But the anguish of his heart was not greater than that which now
filled the bosom of her from whom he was so unexpectedly and
cruelly separated.
CHAPTER L.
THE LAWYER'S OFFICE.

A few days after the events just related, the following scene took
place at Mr. Howard's office in Golden Square.
It was about four in the afternoon, and the lawyer was seated in his
private room, at a table covered with papers, when a clerk entered
and announced that Sir Christopher Blunt and his lady had just
arrived.
"His lady with him—eh!" exclaimed the solicitor. "Well—show them in
at once."
And, accordingly, in a few minutes the worthy knight, with Charlotte
—or, we beg her pardon, Lady Blunt—hanging upon his arm, entered
the office.
The old gentleman was all smiles—but the quick eye of Mr. Howard
immediately perceived that they were to some extent forced and
feigned; and that beneath his jaunty aspect there was not altogether
the inward contentment, much less the lightsome glee, of a happy
bridegroom.
As for Lady Blunt—she was attired in the richest manner, and in all
the colours of the rainbow,—looking far too gaudy to be either
genteel or fashionable.
"My dear Sir Christopher, I am quite charmed to see you" exclaimed
Mr. Howard, rising to welcome his client and the bride. "Your
ladyship——"
"Yes—this is my loving and beloved Lady Blunt, Howard," said the
knight pompously: "a delightful creature, I can assure you—and who
has vowed to devote herself to my happiness."
"Come now, you great stupid!" said the lady; "finish your business
here, and let us see about the new carriage. Of all places in the
world, I hate a lawyer's office—ever since I was once summoned to
a Court of Conscience for seventeen shillings and ninepence-
halfpenny, and had to call on the thief of an attorney to get him to
take it by instalments of sixpence a-week. So, you see, I can't a-bear
the lawyers. No offence, sir," she added, turning towards Mr.
Howard; "but I always speak my mind; and I think it's best."
"My dear creature—my sweet love!" ejaculated Sir Christopher,
astounded at this outbreak of petulance on the part of his loving and
beloved wife.
"Pray do not distress yourself, my dear Sir Christopher," said the
lawyer. "We are accustomed to receive sharp rebukes from the ladies
sometimes," he added, with as courteous a smile as he could
possibly manage under the circumstances. "But pray be seated. Will
your ladyship take this chair?"—and he indicated the one nearest to
the fire.
Lady Blunt quitted her husband's arm, but made an imperious sign
for him to bring his chair close to hers; and he obeyed her with a
submission which left no doubt in the lawyer's mind as to the empire
already asserted by the bride.
"I am very glad you have called to-day, Sir Christopher," said the
lawyer; "for——"
"He couldn't very well come before, sir," interrupted Lady Blunt;
"because we only came back from the matrimonial trip last night."
Mr. Howard bowed, and was preparing to continue, when the knight
exclaimed, "My dear sir, what is all this to-do about the highwayman
who robbed me of the two thousand pounds? I thought I told you so
particularly that I would rather no steps should be taken in the
matter; and now—the moment I come back to town——"
"Instead of having all our time to ourselves, to gad about cozie
together," again interrupted Lady Blunt, "we are forced to come
bothering here at a lawyer's office."
"The ends of justice must be met, Lady Blunt," said Mr. Howard drily.
"In consequence of particular information which I received, I caused
this Thomas Rainford to be apprehended; and I appeal to Sir
Christopher himself—who has served the high office of Sheriff——"
"And once stood as a candidate for the aldermanic gown of
Portsoken, until I was obliged to cut those City people," added the
knight, drawing himself up.
"And why should you cut the City people?" demanded his wife. "For
my part, I'd sooner see the Lord Mayor's show than Punch and Judy
any day; and that's saying a great deal—for no one can be more
fonder of Punch and Judy than me."
"My dear Charlotte," exclaimed the knight, who now seemed to be
sitting on thorns, "you——"
"Charlotte at home—Lady Blunt in public, Sir Christopher—if you
please," interrupted the bride. "But pray let Mr. Howard get to the
end of this business."
"Well, my dear," exclaimed Sir Christopher, "if it annoys you, why
would you come? I assured you how unusual it was for ladies to
accompany their husbands to the office of their solicitors——"
"Oh! I dare say, Sir Christopher!" cried Charlotte. "You don't think
that I'm going to trust you out of my sight, do you now? I'm not
quite such a fool as you take me for. Why, even when we are
walking along the street together, I can see your wicked old eye
fixed on the gals——"
"Lady Blunt!" exclaimed the knight, becoming literally purple; "you—
you—you do me an injustice!"
"So much the better. I hope I am wrong—for both of our sakes,"
returned her ladyship. "Depend upon it——But, no matter now: let
Mr. Howard get on with his story."
"With your permission, madam, I shall be delighted to do so," said
the lawyer. "I was observing just now that having received particular
information, I caused this scoundrel Thomas Rainford, alias Captain
Sparks, to be apprehended; and on Monday morning, Sir
Christopher, you must attend before the magistrate to give your
evidence."
"But who authorised you to proceed in this affair, Mr. Howard?"
demanded the knight.
"What a strange question?" exclaimed the lawyer, evidently unwilling
to give a direct answer to it. "Only reflect for a moment, my dear Sir
Christopher. A robbery is committed—you, your nephew, and myself
are outwitted—laughed at—set at defiance,—and when an
opportunity comes in my way, I very naturally adopt the best
measures to punish the rogue."
"Quite proper too, sir," said Lady Blunt. "The idea of any one daring
to laugh at Sir Christopher! I'd scratch the villain's eyes out, if I had
him here. To laugh at Sir Christopher, indeed! Does he look like a
man who is meant to be laughed at?"
Lady Blunt could not have chosen a more unfortunate opportunity to
ask this question; for her husband at that moment presented so
ludicrous an appearance, between his attempts to look pleasant and
his fears lest he already seemed a henpecked old fool in the eyes of
his solicitor, that a man possessing less command over himself than
Mr. Howard would have laughed outright.
But with the utmost gravity in the world, the lawyer assured her
ladyship that nothing could be more preposterous than to laugh at a
gentleman of Sir Christopher Blunt's rank and importance; and he
also declared that in arresting Thomas Rainford, he had merely felt a
proper anxiety to punish one who had dared to ridicule the knight,
after having robbed him.
Lady Blunt was one of those capricious women who will laugh at
their husbands either as a matter of pastime or for the purpose of
manifesting their own independence and predominant sway, but who
cannot bear the idea of any other person taking a similar liberty. She
therefore expressed her joy that Mr. Howard had caused Rainford to
be apprehended, and declared, of her own accord, that Sir
Christopher should attend to give his evidence on the ensuing
Monday—"for she would go with him!"
"Well, my dear, since such is your pleasure," observed the knight,
"there is no more to be said upon the subject. I will go, my love; and
I think that when the magistrate hears my evidence, he will feel
convinced that I know pretty well how to aid the operation of the
laws, and that I have not been a Sheriff for nothing. Although
sprung from a humble origin——"
"Oh! pray don't begin that nonsense, Sir Christopher!" exclaimed the
lady; "or I shall faint. It is really quite sickening."
At that moment the door opened somewhat violently; and Mr. Frank
Curtis entered the room.
"Ah! Sir Christopher, my jolly old cock—how are you?" exclaimed that
highly respectable young gentleman, whose face was dreadfully
flushed with drinking, and who smelt so strong of cigars and rum-
punch that his presence instantly produced the most overpowering
effect.
"Mr. Curtis!" began the knight, rising from his chair, and drawing
himself up to his full height, "I——"
"Come—it's no use to be grumpy over it, uncle," interrupted Frank.
"Matrimony doesn't seem to agree with you very well, since you're
so soon put out of humour. Ah! my dear Char——my dear aunt, I
mean—beg your pardon—quite a mistake, you know;—but really you
look charming this afternoon."
"Get out with you, do!" cried Lady Blunt, who was somewhat
undecided how to treat Mr. Curtis.
"What! doesn't matrimony agree with you, either, my dear and much
respected aunt?" ejaculated Frank. "Why, I once knew a lady who
was in a galloping consumption—given up, in fact, and the
undertaker who lived over the way had already begun to make her
coffin—for he knew he should have the order for the funeral; when
all of a sudden a young chap fell in love with her, married her, and
took her to the south of France—where I've been, by the bye—and
brought her home in six months quite recovered, and in a fair way to
present him with a little one—a pledge of affection, as it's called."
"Mr. Curtis, I am surprised at you," exclaimed Sir Christopher, in a
pompous and commanding tone;—"to talk in this way before a lady
who has only recently passed through that trying ordeal."
"I'll be bound to say it wasn't so recent as you suppose, old buck,"
cried Frank, staggering against the lawyer's table.
"Sir, Lady Blunt has only been recently—very recently married, as
you are well aware," said the knight sternly. "And now let me tell
you, sir, that the detestable devices schemed by Miss Mordaunt and
you have recoiled upon yourselves——"
"Miss Mordaunt and me!" exclaimed Frank, now unfeignedly
surprised: "why—I never spoke to Miss Mordaunt in my life!"
"The monster!" half screamed Lady Blunt.
"The audacious liar!" vociferated the knight.
"Pretty names—very pretty," said Frank coolly; "but I'm rather tough,
thank God! and so they won't kill me this time. But I can assure you,
uncle, you've got hold of the wrong end of the stick when you say
that me and Miss Mordaunt planned any thing against you. As I once
observed to my friend the Count of St. Omers,—'My lord,' says I.
—'What?' asks the Marquis.—'My Lord Duke,' I repeated, in a firmer
tone——"
"Cease this nonsense, Mr. Curtis," interrupted Sir Christopher Blunt
sternly.
"Yes—and let us come along, my dear," said Lady Blunt, rising and
taking her husband's arm. "Your nev-vy does smell so horrid of rum
and cigars——"
"And very good things too," cried Frank; "ain't they, Howard? Me and
a party of young fashionables have been keeping it up a bit to-day at
my lodgings—on the strength of my intended marriage with Mrs.
Goldberry, the rich widow——"
"Your marriage, Frank!" exclaimed Sir Christopher. "What—how—
when——"
"Lord bless you, my dear uncle," said Mr. Curtis, swaying himself to
and fro in a very extraordinary manner, "you don't half know what
kind of a fellow I am. While you was away honeymooning and
nonsense——"
"Nonsense, indeed!" exclaimed Lady Blunt, indignantly. "Come, Sir
Christopher—it's no good staying here talking to Mr. Imperance."
"Going to Conduit Street—eh, aunt?" said Frank, with a drunken leer.
"But, by-the-bye, you regularly choused me out of five guineas, you
know, aunt—and something else, too——"
"Eh?—what?" said Sir Christopher, turning back. "Mr. Curtis, do you
dare to accuse Lady Blunt——"
"Of having made a very great fool of me, but a much bigger one of
you, old fellow," added Frank; and, snapping his fingers in his
uncle's face, he exclaimed, "I don't care a penny for you, Sir
Christopher! In a few days I shall marry Mrs. Goldberry—you are
very welcome to be as happy as you can with your Abigail there. So
remember, we're cuts in future, Sir Christopher—since you want to
come the bumptious over me."
The knight was about to reply; but his better-half drew him hastily
away from the lawyer's office, saying, "Come along, you great
stupid! What's the use of staying to dispute with that feller?"
The door closed behind the "happy couple;" and Mr. Frank Curtis,
throwing himself into the chair which Lady Blunt had just quitted,
burst out into a tremendous fit of laughter.
"You have gone too far, Frank—a great deal too far," said the lawyer,
shaking his head disapprovingly. "Sir Christopher has been a good
friend to you; and although he has committed an egregious error in
running off with that filly, still——"
"What do I care?" interrupted Frank. "I proposed to Mrs. Goldberry
yesterday—and she accepted me, after a good deal of simpering and
blushing, and so on. She's got five thousand a year, and lives in
splendid style in Baker Street. I made her believe that I wasn't quite
a beggar myself: but all's fair in love and war, as my friend the late
Prince of St. Omers used to say in his cups. But what about this
fellow Rainford? and how the deuce did he come to be arrested?"
"I received information of his residence," answered Howard coolly;
"and I gave him into custody accordingly."
"It's very odd," continued Frank, "but I met him last Sunday night;
and I don't mind telling you that we went into the middle of Hyde
Park and had an hour's wrestling together, to see who was the
better man. I threw him nineteen times running, and he threw me
seven; then I threw him three times—and he gave in. So we cried
'quits' for old scores, and I gave him my word and honour that
nothing would ever be done against him in respect to the little affair
of the two thousand pounds. You may therefore suppose that I'm
rather vexed——"
"The officers had already received instructions to apprehend him at
the time your alleged wrestling match came off," said the lawyer;
"and your evidence will be required next Monday morning."
"And I suppose the whole affair of the robbery will come out?"
observed Curtis interrogatively.
"Decidedly so. You must state the exact truth—if you can," added
Mr. Howard.
"If I can! Damn it, old fellow, that observation is not quite the thing
—coming from you; and if any body else had uttered it, egad! I'd
send him a hostile message to-morrow morning—as I did to my
most valued friend, the Marquis of Boulogne, when I was in Paris. I'll
just tell you how that was——"
"Not now Frank," interrupted the lawyer; "because I'm very busy. It's
getting on for post time—and I have not a minute to spare. But mind
and be punctual at the Borough police-office on Monday morning at
ten."
"Well—if I must, I must," said Curtis. "But, after all, I think it's rather
too bad—for this Sparks, or Rainford, or whatever his name is,
seems a good kind of fellow, after all."
"The law must take its course, Frank," observed the attorney in an
abrupt, dry manner.
Curtis accordingly took his leave, and returned to his lodgings,
where by dint of cold water applied outwardly and soda-water taken
inwardly, he endeavoured to sober himself sufficiently to pay a visit
to Mrs. Goldberry.
For it was literally true that there was such a lady—that she lived in
splendid style in Baker Street—that Frank had proposed to her—and
that he had been accepted;—but we have deemed it necessary to
give the reader these corroborative assurances on our part,
inasmuch as the whole tale would otherwise have appeared nothing
more nor less than one of the innumerable children of Mr. Curtis's
fertile imagination.
CHAPTER LI.
LORD ELLINGHAM IN THE DUNGEON.

Four weeks had elapsed since the arrest of Tom Rain and the
extraordinary adventure which had snatched the Earl of Ellingham
from the great world and plunged him into a narrow—noisome cell.
Yes—four weeks had the nobleman languished in the terrible
dungeon,—ignorant of where his prison-house was situated—why his
freedom was thus outraged—and who were his persecutors.
Every morning, at about eight o'clock, a small trap in the door of his
cell was opened, and food was passed through to him. A lamp had
been given him the day after he became an inmate of the place; and
oil was regularly supplied for the maintenance of the light. His food
was good, and wine accompanied it;—it was therefore evident that
no petty spite nor mean malignity had led to his captivity.
Indeed, the man who brought him his food assured him that no
harm would befall him,—that his imprisonment was necessary to suit
certain weighty and important interests, but that it would not be
protracted beyond a few weeks,—and that the only reason for
placing him in such a dungeon was because it was requisite to guard
against the possibility of an escape.
Often and often had Lord Ellingham endeavoured to render his
gaoler more communicative; but the man was not to be coaxed into
garrulity. Neither did he ever allow the nobleman to catch a glimpse
of his features, when he brought the food to the trap-door. He
invariably stood on one side, and spoke in a feigned tone when
replying to any question to which he did vouchsafe an answer.
The day after his strange and mysterious arrest, Arthur received
from this man the assurances above mentioned; and a considerable
weight was thereby removed from his mind. His imprisonment was
not to be eternal: a few weeks would see the term of the necessity
that had caused it. But still he grieved—nay, felt shocked to think of
the state of suspense in which those who cared for him would
remain during his long absence. This source of affliction he
mentioned to the man who attended upon him; and the reply was to
some extent satisfactory.
"I will supply you with writing materials, and you can address letters
to your friends, stating that sudden business has called you abroad—
to France, for instance; and that you may probably be absent six
weeks. Write in this manner—the excuse will at least allay any
serious fears that may be entertained concerning you; and those
letters shall be sent through the post to the persons to whom they
are addressed. But you must deliver them unsealed into my hands,
that I may satisfy myself as to the real nature of their contents."
Small as the satisfaction resulting from this proceeding could be to
Lord Ellingham, it was still far preferable to the maintenance of a
rigid silence in respect to his friends. He accordingly wrote a laconic
letter in the sense suggested by his gaoler; and addressed copies to
Lady Hatfield, Thomas Rainford, and Mr. de Medina. The next time
his gaoler visited him—or rather, came to the door of the dungeon,
the prisoner was informed that the three letters had been duly
forwarded through the twopenny post.
The reader will scarcely require to be informed of the mental anxiety
which the nobleman suffered during his incarceration. This was
naturally great—very great. He was also frequently plunged in the
most bewildering conjectures relative to the authors, the motives,
and the locality of his imprisonment. Nor less did he grieve—Oh!
deeply grieve, when he thought of the surprise—the alarm—and the
sorrow with which Lady Hatfield on one side and Rainford on the
other must view his mysterious absence. He had left the former with
the intention of seeing the latter, and she would naturally expect him
to return if for no other reason than to give her an account of their
interview; and he had quitted Rainford with the promise to perform
a certain task, and also having pledged himself to use his influence
and his wealth in his behalf.
The idea of the feelings that must be entertained by Rainford
relative to his absence, afflicted him more than any other. That
generous-hearted man had told him to keep his coronet and his
fortune to the prejudice of him—the elder brother, legitimately born;
and yet that interview in Horsemonger Lane Gaol seemed destined
to be the last which they were to have together! What would the
poor prisoner think when the Earl returned not, and when a letter
containing a cold and wretched excuse was put into his hands? Oh!
this was the maddening—maddening thought; and the Earl shrank
from it far more appalled than from the stern reality of his dungeon!
Because Rainford might be judged, and, alas! the law might take its
course—its fatal course—ere he, the Earl, could stretch out a hand
to save that generous-hearted half-brother.
But amidst all the bitter and bewildering reflections which tormented
him during his imprisonment of four weeks in that dungeon of
unknown neighbourhood, there was still a predominant idea—a
gleam of hope, which, apart from the assurance that his captivity
would soon have a term, cheered and animated him often.
For whither will not the rays of Hope penetrate? Even when Hope is
really gone, her work is often done by Despair; and the latter
feeling, in its extreme, is thus often akin to Hope herself.
The hope, then, that cheered and animated the Earl at times, was—
Escape!
Yes: he yearned to quit that dungeon, not so much for his own sake
—oh! not nearly so much, as for that of his half-brother, who was
involved in such peril, and who needed influence and interest to
save him! For the Earl well knew that the law in criminal cases is not
so tardy as in civil matters; and that to take away a man's life, all its
machinery is set into rapid motion—although to settle his claims to a
fortune or to give him justice against his neighbour, it is, heaven
knows! heart-breakingly slow and wearisome!
To send a man to the scaffold, takes but a few weeks at the Old
Bailey:—to decide the right of this man or that man to a particular
estate, or legacy, occupies years and years in the Court of Chancery.
Oh! how thirsty do our legislators appear to drink human blood. How
rapidly all technicalities and causes of delay are cleared away when
the capital offender stands before his judge! A day—perhaps an hour
is sufficient to decide the death of a human being; but half a century
may elapse ere the conflicting claims to an acre of land or a few
thousand pounds can be settled elsewhere.
And, strange—ah! and monstrous, too, is it, that the man who loses
a case in which he sues his neighbour for twenty pounds, may
appeal to another tribunal—have a new trial granted—and, losing
that also, perhaps obtain a third investigation of the point at issue,
and thus three verdicts in that beggarly business! But the man who
is doomed to die—who loses his case against the criminal prosecutor
—cannot appeal to another tribunal. No judges sit solemnly in banco
for him: one verdict is sufficient to take away a life. Away with him
to the scaffold! In this great commercial country, twenty pounds—
consisting of pieces of paper printed upon and stamped with
particular figures—are of more consequence than a being of flesh
and blood! What though this being of flesh and blood may have
others—a wife and children—dependent on him? No matter! Give
him not the chance of a new trial: let one judge and one jury suffice
to consign him to the hangman! There can be no appeal—no re-
investigation for his case, although it be a case of life and death: but
away with him to the scaffold!
What blood-thirsty and atrocious monsters have our law-givers
been: what cruel, inhuman beings are they still, to perpetuate so
abominable—so flagrant—so infamous a state of jurisprudence! For
how many have been hanged, though innocent,—their guiltlessness
transpiring when it is too late! But there is no court of appeal for the
man accused of a capital crime: he is a dog who has got a bad name
—and public opinion dooms him to be hanged, days and weeks
before the jury is sworn or the judge takes his seat to try him!
And wherefore is not this infamous state of the law, which allows
appeals to the case of money-claims, but none to the case of capital
accusations,—wherefore is not this state of the law altered? Because
our legislators are too much occupied with their own party
contentions and strifes;—because they are ever engaged in battling
for the Ministerial benches—the "loaves and fishes" of power:
because it seems to them of more consequence to decide whether
Sir Robert Peel or Lord John Russell shall be Prime Minister—whether
the Conservatives or the Whigs shall hold the reins of power. Or else,
gentle reader, the condition of Greece—or Spain—or Turkey,—or
even perhaps of Otaheite,—is a matter of far greater importance
than the lives of a few miserable wretches in the condemned cells of
criminal gaols!
But, in our estimation—and we have the misfortune to differ from
the legislators of the country—the life of one of those wretches is of
far greater consequence than the state of tyrant-ridden Greece—the
Spanish marriages—the quarrels of the Sultan and his Pachas—or
the miserable squabbles of hypocritical English missionaries and a
French governor in Tahiti. Yes—in our estimation, the life of one man
outweighs all such considerations; and we would rather see half a
session of Parliament devoted to the discussion of the grand
question of the Punishment of Death, than one single day of that
session given to all the foreign affairs that ever agitated in a
Minister's brain.

It was the twenty-eighth day of Lord Ellingham's imprisonment; and


it was about six o'clock on the evening of this day.
The nobleman was at work upon the masonry of his dungeon,—his
efforts being directed to remove the stones from the immediate
vicinity of a small square aperture, or sink in the corner of the cell.

You might also like