C and Python Applications: Embedding Python Code in C Programs, SQL Methods, and Python Sockets Philip Joyce download
C and Python Applications: Embedding Python Code in C Programs, SQL Methods, and Python Sockets Philip Joyce download
https://ebookmass.com/product/c-and-python-applications-
embedding-python-code-in-c-programs-sql-methods-and-python-
sockets-philip-joyce/
https://ebookmass.com/product/python-programming-and-sql-10-books-
in-1-supercharge-your-career-with-python-programming-and-sql-andrew-
reed/
https://ebookmass.com/product/applied-numerical-methods-with-python-
for-engineers-and-scientists-steven-c-chapra/
https://ebookmass.com/product/python-real-world-projects-crafting-
your-python-portfolio-with-deployable-applications-steven-f-lott/
Fundamentals of Python: First Programs, 2nd Edition
Kenneth A. Lambert
https://ebookmass.com/product/fundamentals-of-python-first-
programs-2nd-edition-kenneth-a-lambert/
https://ebookmass.com/product/fortran-with-python-integrating-legacy-
systems-with-python-bisette/
https://ebookmass.com/product/the-python-advantage-python-for-excel-
in-2024-hayden-van-der-post/
https://ebookmass.com/product/coding-for-kids-5-books-in-1-javascript-
python-and-c-guide-for-kids-and-beginners-bob-mather/
https://ebookmass.com/product/data-mining-for-business-analytics-
concepts-techniques-and-applications-in-python-ebook/
Philip Joyce
Apress Standard
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
1. Python Programming
Philip Joyce1
(1) Crewe, UK
This is the first of two chapters in which you’ll review both Python and C programming
languages. A basic understanding of computing and what programs are about is assumed
although no prior knowledge of either Python or C is needed.
In this chapter, we will start with the basics of Python. This will include how items used
in a program are stored in the computer, basic arithmetic formats, handling strings of
characters, reading in data that the user can enter on the command line, etc. Then we will
work up to file access on the computer, which will lead us up to industrial/commercial-level
computing by the end of the book.
If you don’t already have a Python development environment on your computer, you can
download it and the Development Kit, free of charge, from
www.python.org/downloads/. Another way you can access Python is by using Visual
Studio. Again, a version of this can be downloaded.
Definition of Variables
This section looks at the different types of store areas that are used in Python. We refer to
these store areas as “variables.” The different types can be numbers (integers or decimals),
characters, and different types of groups of these (strings, arrays, dictionaries, lists, or
tuples).
In these examples, you can go to the command line and enter “Python” which starts up
the Python environment and produces “>>>” as the prompt for you to enter Python code.
In Python, unlike C, you don’t define the variable as a specific type. The different types
are integer, floating point, character, string, etc. The type is assigned when you give the
variable a value. So try the following code:
>>> a1 = 51
>>> print(type(a1))
We get the output
<class 'int'>
>>>
Here we are defining a variable called “a1” and we are assigning the integer value 51 to
it.
We then call the function “print” with the parameter “type” and “a1” and we get the reply
“class ‘int’”. “type” means that we want to display whether the variable is an integer, floating
point, character, string, etc.
We can now exit the Python environment by typing “quit()”.
We will now perform the same function from a program.
Create a file called “typ1a.py”.
Then enter the following two lines of Python code:
a1=51
print(type(a1))
<class 'int'>
a1=51
print(type(a1))
a1=51.6
print(type(a1))
a1='51'
print(type(a1))
<class 'int'>
<class 'float'>
<class 'str'>
The 51 entered is an int. The 51.6 is a float (decimal) type, and ‘51’ is a string.
We can make the results a little clearer if we use print(“a1 is”, type(a1)).
So our program now reads
a1=51
print("a1 is",type(a1))
a1=51.6
print("a1 is",type(a1))
a1='51'
print("a1 is",type(a1))
and the output is
a1 is <class 'int'>
a1 is <class 'float'>
a1 is <class 'str'>
We can put a comment on our line of code by preceding it with the “#” character.
arith1a.py
Initialize the variables v1, v2, v3, and v4 with integer values.
v1= 2
v2 = 4
v3 = 7
v4 = 8
v5 = v1 + v2
print(v5)
The result is
print(v1+v2)
Now a subtraction:
v6 = v4 - v3
print(v6)
giving
1
Now a multiplication:
v7 = v4 * v3
print(v7)
giving
56
Now a division:
v8 = v4 / v1
print(v8)
giving
4.0
v11 = v2 ** 2
print(v11)
gives
16
v11 = v2 ** v1
print(v11)
gives
16
V1 = 2
V2 = 3.5
V3 = 5.1
V4 = 6.75
we get
print(type(V1))
<class 'int'>
print(type(V2))
<class 'float'>
print(type(V3))
<class 'float'>
print(type(V4))
<class 'float'>
Characters
In Python, you can also assign characters to locations, for example:
c1 = 'a'
print(type(c1))
produces
<class 'str'>
Reading in Data
Now that we can display a message to the person running our program, we can ask them to
type in a character, then read the character, and print it to the screen. This section looks at
how the user can enter data to be read by the program.
If we type in the command
vara = input()
print(vara)
which prints
r5
We can make this more explicit by using
You can also make the entry command clearer to the user by entering
Now that we can enter data manually into the program, we will look at groups of data.
Arrays
An array is an area of store which contains a number of items. So from our previous section
on integers, we can have a number of integers defined together with the same label. Python
does not have a default type of array, although we have different types of array.
So we can have an array of integers called “firstintarr” with the numbers 2, 3, 5, 7, 11,
and 13 in it. Each of the entries is called an “element,” and the individual elements of the
array can be referenced using its position in the array. The position is called the “index.” The
elements in the array have to be of the same type. The type is shown at the beginning of the
array.
The array mechanism has to be imported into your program, as shown as follows:
The ‘i’ in the definition of firstintarr means that the elements are integers.
And we can reference elements of the array using the index, for example:
v1 = firstintarr[3]
print(v1)
This outputs
We can also define floating point variables in an array by replacing the “i” by “f” in the
definition of the array.
So we can define
varfloat1 = firstfloatarr[1]
print(varfloat1)
Once we have our array, we can insert, delete, search, or update elements into the array.
Array is a container which can hold a fix number of items, and these items should be of
the same type. Most of the data structures make use of arrays to implement their
algorithms. The following are the important terms to understand the concept of array:
Insert
Delete (remove)
Search
Update
Append
Let’s review them now.
for x in myarr:
print(x)
This outputs
2
13
3
5
7
11
for x in myarr:
print(x)
This outputs
3
5
7
11
Searching
The following code is in the file array5.py:
This outputs
Updating an Array
The following code is in the file array6.py:
array6.py
for x in myarr:
print(x)
This outputs
2
3
17
7
11
Appending to an Array
The following code is in the file array9a.py:
array9a.py
for x in myarr:
print(x)
2
3
5
7
11
Enter an integer: 19
Strings
Strings are similar to the character arrays we discussed in the previous section. They are
defined within quotation marks. These can be either single or double quotes. We can specify
parts of our defined string using the slice operator ([ ] and [:]). As with character arrays, we
can specify individual elements in the string using its position in the string (index) where
indexes start at 0.
We can concatenate two strings using “+” and repeat the string using “*”.
We cannot update elements of a string – they are immutable. This means that once they
are created, they cannot be amended.
The following code:
firststring = 'begin'
print(firststring)
gives
begin
one = 1
two = 2
three = one + two
print(three)
#gives
3
cond st
print(secondstring[2:9:1]) # The general form is
[start:stop:step] giving
cond st
print(secondstring[::-1]) # Reverses the string giving
gnirts dnoces
second= "second"
second[0]="q"
we get
Traceback (most recent call last):
Lists
Lists are similar to arrays and strings, in that you define a number of elements, which can be
specified individually using the index. With lists, however, the elements can be of different
types, for example, a character, an integer, and a float.
The following code is in the file alist7.py:
print(firstlist[0])
gives
k
print(firstlist[1:3])
gives
[97, 56.42]
firstlist[3] = 'plj'
print(firstlist)
giving
['k', 97, 56.42, 'plj', 'bernard']
del firstlist[3]
print(firstlist)
giving
['k', 97, 56.42, 'bernard']
firstlist.append(453.769)
print(firstlist)
giving
['k', 97, 56.42, 'bernard', 453.769]
This outputs
list1: ['first', 'second', 'third']
list1[0]: first
list2: [1, 2, 3, 4, 5]
list2[3]: 4
list2[:3]: [1, 2, 3]
list2[2:]: [3, 4, 5]
list2[1:3]: [2, 3]
Updating a List
The following code is held in the file alist2a.py:
alist2a.py
list1 = [1, 2, 3, 4, 5 ]
This outputs
list1: [1, 2, 3, 4, 5]
updated list1: [1, 26, 3, 4, 5]
alist3a.py
list1 = [1,2,3,4,5,6]
print (list1)
del list1[4]
print ("Updated list1 : ", list1)
This outputs
[1, 2, 3, 4, 5, 6]
Updated list1 : [1, 2, 3, 4, 6]
Appending to a List
The following code is held in the file alist4aa.py:
alist4aa.py
list2 = [10,11,12,13,14,15]
print (list2)
new = int(input("Enter an integer: "))
list2.append(new)
print(list2)
This outputs (if you enter 489)
Dictionaries
Dictionaries contain a list of items where one item acts as a key to the next. The list is
unordered and can be amended. The key-value relationships are unique. Dictionaries are
mutable.
Creating a Dictionary
In the first example, we create an empty dictionary. In the second, we have entries.
firstdict = {}
or
firstdict ={'1':'first','two':'second','my3':'3rd'}
Appending to a Dictionary
The following code is held in the file adict1a.py:
adict1a.py
#create the dictionary
adict1 = {'1':'first','two':'second','my3':'3rd'}
print (adict1)
print (adict1)
This outputs
{'1': 'first', 'two': 'second', 'my3': '3rd'}
second
{'1': 'first', 'two': 'second', 'my3': '3rd', 4: 'four'}
4
If we want to add value whose key is dinsdale, then we specify it as ‘dinsdale’.
So
adict1['dinsdale'] = 'doug'
print (adict1)
outputs
Amending a Dictionary
The following code is held in the file adict2a.py.
This amends the value whose key is ‘two’ to be '2nd'.
adict2a.py
adict1 = {'1':'first','two':'second','my3':'3rd'}
adict1['two'] = '2nd'
print(adict1)
This outputs
adict3a.py
adict1 = {'1':'first','two':'second','my3':'3rd'}
print(adict1)
del adict1['two'] #this deletes the key-value pair whose key is
'two'
print(adict1)
This outputs
adict5aa.py
print("Enter key to be tested: ")
testkey = input()
my_dict = {'a' : 'one', 'b' : 'two'}
print (my_dict.get(testkey, "none"))
This outputs (if you enter “a” when asked for a key)
Enter key to be tested:
a
one
or outputs (if you enter “x” when asked for a key)
Enter key to be tested:
x
none
We have seen what dictionaries can do. We now look at tuples.
Tuples
A tuple contains items which are immutable. The elements of a tuple can be separated by
commas within brackets or individual quoted elements separated by commas. They are
accessed in a similar way to arrays, whereby the elements are numbered from 0. In this
section, we will look at creating, concatenating, reading, deleting, and searching through
tuples.
For example, define two tuples called firsttup and secondttup:
firsttup[2]
gives
c
firsttup[3]
gives
1
secondtup = "a", "b", 10, 25
The following code refers to the second element of secondtup:
secondtup[1]
gives
b
secondtup[2]
gives
10
We can also use negative indices to select from the end and work backward, for example,
secondtup[-1]
which gives
25
secondtup[-2]
which gives
10
we would get
Creating a Tuple
# An empty tuple
empty_tuple = ()
print (empty_tuple)
()
tuple1 = (0, 1, 2, 3)
tuple2 = ('first', 'second')
tuple1 = (0, 1, 2, 3)
tuple2 = ('first', 'second')
tuple3 = (tuple1, tuple2)
print(tuple3)
gives
((0, 1, 2, 3), ('first', 'second'))
tuple3 = ('first',)*3
print(tuple3)
gives
('first', 'first', 'first')
list1 = [0, 1, 2]
print(tuple(list1))
(0, 1, 2)
print(tuple('first')) # string 'first'
('f', 'i', 'r', 's', 't')
Reading Tuple
# Reading from start (index starts at zero)
tup1=(2,3,4,5,6,7)
tup[3]
gives
5
Deleting a Tuple
# Deleting a complete Tuple
del tup1
print(tup1)
gives
We have covered definitions and uses of different types of variables in this section. We
will now look at the use of “if” statements.
If Then Else
When a decision has to be made in your program to either do one operation or the other, we
use if statements.
These are fairly straightforward. Basically, we say
if (something is true)
Perform a task
if (a condition is true)
Perform a task
else if it does not satisfy the above condition
Perform a different task
number = 5
if number > 3:
print('greater than 3')
number = 5
if number > 3:
print('greater than 3')
else:
print('not greater than 3')
Type in this code into a program and run it. It should come as no surprise that the output
is
greater than 3
You could modify the program so that you input the number to be tested, but don’t forget
that for this code you need number = int(input (“Enter number :”)) to enter a number.
This section has shown the importance of “if” statements in programming. Now we will
look at loops.
For Loops
Here is an example of how a for loop can help us.
The statement is
'for x in variable
Carry out some code'
outputs
20
13
56
9
number = 1
total = 1
for x in range(10): ): #so here start is 0 (default), stop is 10-
1, and step is 1
total = total * number
number = number + 1
print(total)
This outputs
3628800
This outputs
3
4
5
We can also have a list of values instead of a range, as shown in the next program.
This goes through the values and finds the index position of the value 46. We can see that
46 is in position 9 (counting from 0) .
forloopvar1 = [20, 13, 56, 9, 32, 19, 87, 51, 70, 46, 56]
count = 0
for x in forloopvar1:
if x == 46:
break
count = count + 1
print(count)
This outputs
While Loops
The logic of “while” loops is similar to our for loops .
Here, we say
'while x is true
Carry out some code'
So we could have the following code which keeps adding 1 to count until count is no
longer less than 10. Within the loop, the user is asked to enter integers. These are added to a
total which is printed out at the end of the loop.
total = 0;
number = 0
# while loop goes round 10 times
while number < 10 :
total = total + n
number = number + 1
print('Total Sum is = ', total)
So if the user enters the number shown in the following, we get the total:
Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: 8
Enter a number: 9
Enter a number: 10
Total Sum is = 55
We have seen the importance of loops in this section. Our next section looks at switches.
Switches
In C programming, there is an instruction used widely called “switch.” However, because
there is no switch statement in Python, this section will demonstrate some code that can be
included into your programs to perform the same function.
A switch jumps to a piece of code depending on the value of the variable it receives. For
instance, if you had to perform different code for people in their 30s to that for people in
their 40s and different to people in their 50s, we could have the following code. Here we
have the value in “option” which determines which code we jump to.
The code for this function is in the file aswitch3.py:
aswitch3.py
def switch(option):
if option == 30:
print("Code for people in their 30s")
elif option == 40:
print("Code for people in their 40s")
else:
print("Incorrect option")
#main code in the program where you enter 30,40 or 50 and the
function 'switch' is called which uses the appropriate number as
shown.
optionentered = int(input("enter your option (30, 40 or 50 : )
"))
switch(optionentered)
running this program and entering '50' gives
enter your option : 50
Code for people in their 50s
This section has shown how to perform a switch in Python. We now move onto an
important library of functions in Python. This is called “numpy.”
It is particularly useful in manipulating matrices (or arrays with extra dimensions). The
arrays we have looked at so far are one-dimensional arrays. In this section, we will look at
arrays with more dimensions. A one-dimensional array can also be called a “rank 1 array.”
We import numpy into our program using “import numpy”, and we assign a link for our
program. Here we define the link as “np” so the full line of code is
import numpy as np
The numpy function “shape” returns the dimensions of the array. So if your array was
defined as
b = np.array([[1,2,3],[4,5,6]])
then the array would be a 2x3 matrix (two rows and three columns) as shown as follows:
[[1 2 3]
[4 5 6]]
So if you now type
print(b.shape)
(2, 3)
as the shape.
The code for this function is in the file numpy1.py:
import numpy as np
#1 2 3
#4 5 6
# reference elements counting from 0
# so b[1, 2] is row 1 (2nd row) column 2 (3rd column)
#so if you print b[1, 2] you get 6
print("b[1, 2] follows")
print(b[1, 2])
This is what we have defined in the preceding code using the following line of code:
Matrix arithmetic can be understood by looking at real-life examples. The following are
tables of three people working for a computer company. The first table shows how many
laptops and how many printers each person sells in a month.
In Store Sale
The next table shows how many laptops and printers each person has sold online.
Online Sale
These tables can be represented by matrices as shown in the following. We add each
term in the first matrix to the corresponding term in the second matrix to give the totals
shown in the third matrix.
The next table shows the total of laptops and printers sold by each person:
Total/Overall Sale
If each person doubles their total sales the following month, we can just multiply their
current sales total by 2 as shown as follows:
We now look at their totals for the first month and have another table containing the cost of
a laptop and the cost of a printer.
Total Sales
Person Laptops Printers Cost/Item list with
cost
Joe 10 27 Laptop 200
Mary 27 31 Printer 25
Jen 48 26
We can work out how much money each person makes for the company my multiplying
their total number of sales of a laptop by its cost. Then we multiply their total number of
sales of printers by its cost and then add these two together. The table and the
corresponding matrix representations of this are shown as follows:
Sales Cost
Joe 10x200 + 27x25 = 2975
Mary 27x200 + 31x25 = 3875
Jen 48x200 + 26x25 = 4775
There is a rule when multiplying matrices. The number of columns in the first matrix has
to be equal to the number of rows of the second matrix.
So if we say that a matrix is 2x3 (two rows and three columns), then it can multiply a 3x2
or a 3x3 or a 3.4, etc. matrix. It cannot multiply a 2x3 or 2x4 or 4x2 or 4x3, etc.
In the multiplication in the preceding diagram, we see it is (3x2) x (2x1) producing a (3x1)
matrix.
Numpy Calculations
Listings 1-1 through 1-5 are some programs to show basic numpy calculations with
matrices.
Add two 2x2 matrices.
import numpy as np
a = np.array(([3,1],[6,4]))
b = np.array(([1,8],[4,2]))
c = a + b
print('matrix a is')
print(a)
print('matrix b is')
print(b)
print('matrix c is')
print(c)
Listing 1-1 numpmat.py
This outputs
matrix a is
[[3 1]
[6 4]]
matrix b is
[[1 8]
[4 2]]
matrix c is
[[ 4 9]
[10 6]]
import numpy as np
a = np.array(([1,2,3],[4,5,6]))
b = np.array(([3,2,1],[6,5,4]))
d = a + b
c = 2*a
print('matrix a is')
print(a)
print('matrix b is')
print(b)
print('matrix d is')
print(d)
print('matrix c is')
print(c)
Listing 1-2 numpmat2.py
This outputs
matrix a is
[[1 2 3]
[4 5 6]]
matrix b is
[[3 2 1]
[6 5 4]]
matrix d is
[[ 4 4 4]
[10 10 10]]
matrix c is
[[ 2 4 6]
[ 8 10 12]]
Add a 2x2 matrix to a 2x2 matrix both floating point.
import numpy as np
a = np.array(([3.1,1.2],[6.3,4.5]))
b = np.array(([1.3,8.6],[4.9,2.8]))
c = a + b
print('matrix a is')
print(a)
print('matrix b is')
print(b)
print('matrix c is')
print(c)
Listing 1-3 numpmat3.py
This outputs
matrix a is
[[3.1 1.2]
[6.3 4.5]]
matrix b is
[[1.3 8.6]
[4.9 2.8]]
matrix c is
[[ 4.4 9.8]
[11.2 7.3]]
import numpy as np
a = np.array(([1,2],[4,5],[6,8]))
b = np.array(([3],[6]))
print('matrix a is')
print(a)
print('matrix b is')
print(b)
print('matrix c is')
print(c)
Listing 1-4 numpmat4.py
This outputs
matrix a is
[[1 2]
[4 5]
[6 8]]
matrix b is
[[3]
[6]]
matrix c is
[[15]
[42]
[66]]
Note the way you do the multiplication by hand, 1st row x 1st column, 1st row x 2nd
column, 1st row x 3rd column, then 2nd row, and then 3rd row. Of course, if you use
numpy’s matmul function, it is all done for you.
import numpy as np
a = np.array(([1,2],[3,4],[5,6]))
b = np.array(([7,8,9],[10,11,12]))
c = np.matmul(a,b)
print('matrix a is')
print(a)
print('matrix b is')
print(b)
print('matrix c is')
print(c)
Listing 1-5 numpmat5.py
This outputs
matrix a is
[[1 2]
[3 4]
[5 6]]
matrix b is
[[ 7 8 9]
[10 11 12]]
matrix c is
[[ 27 30 33]
[ 61 68 75]
[ 95 106 117]]
This section has explored the important numpy mathematical functions in Python.
The program here is going to plot a graph of the marks that people got in an
examination.
The code for this function is in the file mp1a.py:
mp1a.py
import matplotlib.pyplot as plt
# x values:
marks = list(range(0, 100, 10)) #marks (x values) divided into
equal values up to 100
print(marks) # write the values calculated by the previous
instruction
This produces
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
# y values:
people = [4, 7, 9, 17, 22, 25, 28, 18, 6, 2]
# label the axes
plt.xlabel('marks')
plt.ylabel('people')
plt.plot(marks, people)
plt.show()
and outputs
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
We see from the graph that most people got marks between about 30 and 70, which is
what you would expect. A few got low marks and only a few got high marks.
The next program, mp2aa.py, plots two graphs on the same axes. Here we plot
examination marks gained by females and those gained by males. We plot females as one
color and males as another.
The code for this function is in the file mp2aa.py:
Other documents randomly have
different content
CHAPTER CXXX.
PERDITA.
A week had elapsed since the arrival of Mrs. and Miss Fitzhardinge in
the great metropolis; and as yet they appeared to be no nearer to
an acquaintanceship with Charles Hatfield than they were on the day
when they first beheld him issue from Lord Ellingham’s mansion;—
for that it was he whom they had seen on the occasion alluded to,
the mother had satisfactorily ascertained.
Indeed, the old woman had not been idle. Every evening, for a
couple of hours, did she watch in the immediate vicinity of the Earl’s
dwelling to obtain an interview with the young man: but he did not
appear to go out after dusk.
Unhesitatingly accosting him, she said, “Mr. Hatfield, will you accord
me your attention for a few moments?”
The young man turned towards her, and beheld a very ugly, plainly-
attired, old lady: he nevertheless answered her respectfully, because
she had addressed him in a manner denoting genteel breeding. We
should observe, too, that she had purposely assumed a humble
apparel on the occasion of these evening watchings, in order to
avoid the chance of attracting the attention of passers-by or
policemen, who would naturally have wondered to see a handsomely
apparelled person thus loitering about.
“I know well who lives there, Mr. Hatfield,” answered the old woman;
“and it is precisely because I wish to speak to you alone, that I have
accosted you in the street. Can you pardon such boldness?”
“Ah! what did you say?” ejaculated the young man, starting as if a
chord had been touched so as to vibrate to his very heart’s core.
“I mean that if you refuse to accompany me, you will repent the loss
of an opportunity to receive revelations nearly concerning yourself,
and which opportunity may not speedily occur again.”
“Who are you? and what do you know of me?” demanded Charles,
breaking silence abruptly after more than a minute’s pause, and
speaking in a tone of earnestness denoting mingled suspense,
wonder, and curiosity.
“My name is Fitzhardinge,” replied the old woman; “and I know all—
every thing concerning you,—aye, much more than you can possibly
suspect. But not another word of explanation will I utter here; and
you may now decide whether you will at once accompany me——”
The old woman and the young gentleman now proceeded in silence
towards Suffolk Street, Pall Mall—the latter wondering who his
companion might be, what she could possibly have to communicate
to him, and how she had acquired the information which she alleged
to be so important and was about to impart. He naturally associated
the promised revelations with the mysterious circumstances which
he had so recently fathomed by means of the letters and
manuscripts found in the secret recess of the library at Lord
Ellingham’s mansion;—and yet he was at a loss to conceive how a
Mrs. Fitzhardinge, whose name was entirely strange to him, could
possibly have any connexion with his own family affairs. At one
moment he fancied that the proceeding on her part was nothing
more nor less than a plot to inveigle him to some den for predatory
purposes: for he had heard that London abounded in such horrible
places, and also in persons who adopted every kind of stratagem to
lure the unwary into those fatal snares. But when he considered the
quarter of the great metropolis in which his companion evidently
resided, as she had assured him that her abode was only a few
minutes’ walk from the spot where she had first accosted him,—
when he again noticed the respectability of her appearance, and
reflected that there was something superior in her manners,
language, and address,—and lastly, when he remembered that
amidst circumstances so complicated and mysterious as those which
regarded his own family, it was highly possible for that aged female
to be interested in them in some way or another,—he blamed
himself for his misgivings, and resolved to see the end of the
adventure.
Scarcely was his mind thus made up, when Mrs. Fitzhardinge turned
into Suffolk Street; and in less than another minute, she knocked in
an authoritative manner at the door of a handsome house. The
summons was instantaneously responded to by a respectable
female-servant; and Charles Hatfield followed the old lady up a wide
stair-case lighted by a lamp which a statue in a niche held in its
hand. On reaching the first landing, Mrs. Fitzhardinge threw open a
door, saying, “Walk into this room, Mr. Hatfield: I will join you in a
few moments.”
She had heard him ascending the stairs—and she had purposely
placed herself in an attitude which should seem as if he had
disturbed her unexpectedly, and thus serve as an apology for the
negligent abandonment of limb which gave to her position an air
alike wanton and lascivious. While she, therefore, affected to gaze
on him in soft surprise, he was intently devouring her with looks of
unfeigned amazement;—and while she still retained that voluptuous
attitude as if unwittingly, he was rivetted to the spot near the door
where he had stopped short on first catching sight of her. This
dumb-show on the part of both,—artificial with her, and real with
him,—lasted for nearly a minute;—and during that time Perdita had
an opportunity of surveying the young man’s handsome appearance
with even more searching scrutiny than when she had seen him in
Pall Mall the very day of her arrival in London,—while, on his side,
Charles Hatfield had leisure to scan a combination of charms such as
transcended all his ideal creations, and which, had he beheld them
in a picture, he would have declared to be impossible of realization.
“No excuse is necessary, sir,” replies Perdita; “The lady whom you
state to have conducted you hither, is my mother; and she has
doubtless sought her chamber for a few minutes to change her
attire. Pray be seated.”
But Charles Hatfield once more stood still—rivetted to the spot, after
having advanced a few paces towards Perdita;—for the sound of her
voice, so sweetly musical—so enchantingly harmonious, appeared to
inspire him with ecstatic emotions and infuse an ineffable delight
into his very soul.
Then Perdita arose from the sofa, and indicating a chair close by,
again invited the young man to be seated,—accomplishing this
courtesy with so ravishing a grace and such a charming smile, that
he felt himself intoxicated—bewildered—enchanted by the magic of
her beauty, the melody of her silver tones, and the soft persuasion
of her manner. For the consciousness of almost superhuman beauty
had rendered Perdita emulative of every art and taught her to study
every movement which might invest her with a winning way and a
witching power;—and thus this singular young woman had acquired
a politeness so complete that it seemed intuitive, and a polish so
refined that it appeared to have been gained by long and unvaried
association with the highest classes.
Sinking into the chair thus gracefully offered him, Charles Hatfield
could not take his eyes off the magnificent creature who remained
standing for a few seconds after he was seated; for, affecting to alter
the position of one of the wax candles on the mantel, as if it were
too near the mirror, she placed herself in such an attitude that the
young man might obtain a perfect view of the flowing outlines of her
glorious form,—the splendid arching of the swan-like neck—the
luxurious fulness of the bust—the tapering slenderness of the waist
—the plump and rounded arms—the large, projecting hips—and the
finely proportioned feet and ankles.
“My mother will not be many minutes, sir,” said Perdita, now
returning to her seat upon the sofa; “and in the meantime I must
solicit you to exercise your patience—for I am afraid you will find me
but a dull companion.”
“Then you have not long resided in London, Miss Fitzhardinge?” said
Charles, hazarding this mode of address with the determination of
ascertaining whether the beautiful young woman were married or
single.
“We have only been in this city for one week,” she replied in an
acquiescent way which convinced him that she had not changed the
parental name by means of wedlock—a discovery that infused a
secret glow of pleasure into his very soul, though at the same
instant his heart smote him as if he were already playing a
treacherous part in respect to Lady Frances Ellingham. “No,”
continued Perdita, “we have not long resided in London. Urgent
affairs have compelled my mother to visit the capital; and as our
stay is likely to be of considerable duration, we are about to take a
house. For my part, I am not sorry that we are thus to settle in
London: for, in spite of its oppressive atmosphere, its smoke, and its
noise, it has many attractions.”
Perdita saw what was passing in his mind: at least, she perceived
that he repented of the proposal which he had so precipitately
made, and which it had rejoiced her so much to receive;—and she
resolved to conquer his scruples—overcome his repugnance—and
confirm him in the act of vassalage to which her transcendent
charms and her wanton arts had already prompted him.
Laying her soft warm hand upon his, and approaching her
countenance so near to his own that her fragrant breath fanned his
cheek, she said, in a tone apparently of deep emotion, “Mr. Hatfield,
this proposal is so generous—so kind—so unexpected, that I know
not how to answer you otherwise than by expressing my sincere
gratitude. And yet—so frankly have you made the offer, that it would
be a miserable affectation on my part to hesitate or to appear leas
candid and open in accepting it. I do therefore accept it, my dear sir
—and with renewed thanks. And think not that in constituting
yourself the friend—for in such a light must I henceforth consider
you—of Miss Fitzhardinge, you are doing aught derogatory to
yourself. No: for my mother is descended from an old and illustrious
family,—a family which has enumerated amongst its members
personages of rank, eminence, and renown;—and should the
Chancery suit which she has come to London to prosecute, result
favourably to her, she will recover an enormous fortune that has
been accumulating for years through remaining in a dormant state.”
“And are you acquainted with the nature of the business concerning
which Mrs. Fitzhardinge desired to speak with me?” inquired the
young man, wondering why the old lady did not make her
appearance.
“I was told before I came to London that the gentlemen of the great
metropolis were very fond of paying silly young ladies vain and
empty compliments,” said Perdita, looking with good-humoured
archness at her companion, while her eyes beamed with wickedness
and her bosom heaved visibly.
“Is it the first time that you have been assured of your beauty?”
asked Charles, still carried away by an uncontroullable influence.
“Again you compliment me, Mr. Hatfield,” said Perdita, looking down
and blushing,—for even her very blushes she could command at
pleasure. “In reference, however, to the observation you have just
made, I should remark that I have never yet met with one of your
sex whom I could comprehend fully and who could understand me. I
admire openness, candour and sincerity,—that generous frankness,
too, which at once establishes friendship and dissipates cold
formality. For I believe that the trammels of ceremonial politeness
positively spoil the heart,—tutoring it to curb its enthusiasm where
enthusiasm would be so natural! I know not how to express myself
clearly; but what I mean to imply is this—that I am a believer in the
possibility of friendship at first sight——”
“You speak as if you were under an apprehension that you are doing
wrong?” said Perdita, in a tone of soft reproach. “Oh! is this candour
and frankness? If you regret that you have pledged me your
friendship—for such I augur of your words—I release you, Mr.
Hatfield, from the bond: nay—I should be too proud to ask you to
adhere to it!”
And now the young man beheld the fascinating woman in a new
phasis of her charms;—for, with that ready versatility of aspect and
demeanour which she had so completely at her command, she
suddenly invested herself with all the majesty of sublime
haughtiness;—no longer melting, tender, wanton, and voluptuous as
Venus—but terrible, domineering, superb, and imperious as Juno,—
no longer wearing the cestus of the Goddess of Love—but grasping,
as the Queen of Heaven, the thunders of Olympian Jove.
Rising from his suppliant posture, and now taking a seat by the side
of Perdita on the sofa,—relinquishing her hands at the same time,
for fear of giving offence by retaining them,—the infatuated young
man, drunk with passion, said in a low murmuring tone, “We have
not been acquainted more than one hour, and we have exchanged
vows of friendship—is it not so?”
“Yes—if you do not repent now, and never will repent of that pledge
on your part,” answered the dangerous young woman, who thus
conducted her designing machinations with such consummate skill.
“Every thing connected with you seems to be imbued with deep and
enthralling interest, my dear friend,” said Charles: “a supernatural
halo appears to surround you! Your beauty is of a nature so superior
to aught of female loveliness that I ever before beheld—your voice
has something so indescribably melting and musical that it awakens
echoes in the inmost recesses of the soul—your history is strange,
wild, and impressive in its very commencement—your disposition is
characterised by a frankness and candour so generous that it
inspires and reciprocates profound friendship the instant it meets a
kindred spirit—and then there is about you a something so witching,
so captivating, so enchanting, that the best and most virtuous of
men would lose all sense of duty, did you—sweet syren that you are
—undertake to lead them astray.”
“If I have indeed found a kindred spirit in you, Charles,” said Perdita,
taking his hand and pressing it as if in grateful and innocent rapture
to her heaving bosom—an act which only tended to inflame the
young man almost to madness,—“I shall have gained that which I
have long sought, and never yet found. For my heart has hitherto
been as complete a stranger to a sincere friendship as to love! When
I spoke ere now of our friends in the country, I meant those
acquaintances whom custom denominates by the other title.”
“And you will return to visit me to-morrow?” said the young woman,
her fine grey eyes beaming with an unsettled lustre, as if the
mingled voluptuousness of day and night met in those splendid,
eloquent orbs.
“Yes—oh! yes!” cried Charles, as if it were unnecessary to have
asked the question. “And now I shall leave you, Perdita: I shall
depart to feast my imagination on the pleasures of this interview.”
Thus speaking, the young man pressed Perdita’s hand to his lips,
and hurried from the room, intoxicated with a delirium of bliss, and
scarcely conscious of where he was or whither he was going.
CHAPTER CXXXI.
THE SYREN’S ARTS AND CHARMS.
He had found his way into Saint James’s Park; and hurrying to the
most secluded quarter, he was still giving rein to the luxuriousness of
his thoughts, when it suddenly flashed to his mind that he had not
received from the lips of Mrs. Fitzhardinge the important
communications which she had promised him. Indeed, he had not
seen her again from the moment when she showed him into the
drawing-room where he had found the lovely creature to whom his
friendship—his eternal friendship was so solemnly plighted.
But scarcely had these thoughts passed through his brain, when his
heart smote him painfully—severely,—reproaching him with his
treachery towards Lady Frances Ellingham, and suggesting a
comparison between the retiring, bashful beauty of this charming
young creature, and the warm, impassioned, bold loveliness of the
syren Perdita.
The more Charles Hatfield pondered upon the strange scene that
had taken place in Suffolk Street, the less satisfied did he feel with
himself. He saw that his conduct had been rash, precipitate, and
thoughtless;—and yet there was something so pleasurable in what
he blamed himself for, that he was not altogether contrite. Indeed,
he felt—he admitted to his own secret soul, that had he the power
of recalling the last two hours, he should act precisely in the same
manner over again. For when he thought of Perdita,—remembered
her witcheries—dwelt on her faultless charms—and recalled to mind
the mystic fascination of her language and the delicious tones of her
voice,—his imagination grew inflamed—his blood ran rapidly and
hotly in his veins—and it seemed that were she Satan in female
shape, he could sell his soul to her!
When he retired to rest, and sleep did at last visit his eyes, that
beauteous image followed him in his dreams. He thought that he
was seated by the side of the witching fair one on the sofa, and that
she was reclining, half-embraced, on his breast, with her
countenance, flushed and wanton in expression, upturned towards
his own. This delicious position appeared to last for a long—long
time, neither uttering a word, but drinking deep draughts of love
from each other’s eyes. Then he fancied that he stooped to press his
lips to her delicious mouth;—but at that instant the lovely face
changed—elongating, and undergoing so horrible a transformation
that his eyes were fixed in appalling fascination upon it,—while, at
the same time, he became sensible that the soft and supple form
which he held in his arms was undergoing a rapid and signal change
likewise,—till the whole being, lately so charming, so tender, and so
loving, was changed into a hideous serpent. A terrible cry escaped
him—and he awoke!
“And was that dream a reflex of any thoughts which occupy you
when awake?” asked his father, in a kind and anxious tone.
“Dear father, why will you press me on the subject?” cried the young
man, now brought to himself, yet knowing not how to reply. “Oh!
believe me—believe me, it will be better for us both that you do not
persist in questioning me!”
The young man had expected that his father was about to speak on
some of those family matters into the mysterious depths of which he
had penetrated; and, therefore, when Mr. Hatfield addressed to him
that species of interrogative accusation, Charles experienced a relief
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookmasss.com