100% found this document useful (1 vote)
26 views

C and Python Applications: Embedding Python Code in C Programs, SQL Methods, and Python Sockets Philip Joyce all chapter instant download

C

Uploaded by

kehshedyl
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
26 views

C and Python Applications: Embedding Python Code in C Programs, SQL Methods, and Python Sockets Philip Joyce all chapter instant download

C

Uploaded by

kehshedyl
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Download the full version of the ebook at

https://ebookmass.com

C and Python Applications: Embedding Python


Code in C Programs, SQL Methods, and Python
Sockets Philip Joyce

https://ebookmass.com/product/c-and-python-
applications-embedding-python-code-in-c-programs-
sql-methods-and-python-sockets-philip-joyce/

Explore and download more ebook at https://ebookmass.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Python Programming and SQL: 10 Books in 1 - Supercharge


Your Career with Python Programming and SQL Andrew Reed

https://ebookmass.com/product/python-programming-and-sql-10-books-
in-1-supercharge-your-career-with-python-programming-and-sql-andrew-
reed/
testbankdeal.com

Applied Numerical Methods with Python for Engineers and


Scientists Steven C. Chapra

https://ebookmass.com/product/applied-numerical-methods-with-python-
for-engineers-and-scientists-steven-c-chapra/

testbankdeal.com

Top 10 Hacking Scripts in Python, C#, and ASP.NET: 2 Books


in 1: Unmasking Cyber Secrets: Python, C#, and ASP.NET
Scripts to Propel Your Hacking Journey Devwebtuts
Publishing
https://ebookmass.com/product/top-10-hacking-scripts-in-python-c-and-
asp-net-2-books-in-1-unmasking-cyber-secrets-python-c-and-asp-net-
scripts-to-propel-your-hacking-journey-devwebtuts-publishing/
testbankdeal.com

Python Real-World Projects: Crafting your Python Portfolio


with Deployable Applications Steven F. Lott

https://ebookmass.com/product/python-real-world-projects-crafting-
your-python-portfolio-with-deployable-applications-steven-f-lott/

testbankdeal.com
Fundamentals of Python: First Programs, 2nd Edition
Kenneth A. Lambert

https://ebookmass.com/product/fundamentals-of-python-first-
programs-2nd-edition-kenneth-a-lambert/

testbankdeal.com

Fortran with Python: Integrating legacy systems with


Python Bisette

https://ebookmass.com/product/fortran-with-python-integrating-legacy-
systems-with-python-bisette/

testbankdeal.com

The Python Advantage: Python for excel in 2024 Hayden Van


Der Post

https://ebookmass.com/product/the-python-advantage-python-for-excel-
in-2024-hayden-van-der-post/

testbankdeal.com

Coding for Kids 5 Books in 1: Javascript, Python and C++


Guide for Kids and Beginners Bob Mather

https://ebookmass.com/product/coding-for-kids-5-books-in-1-javascript-
python-and-c-guide-for-kids-and-beginners-bob-mather/

testbankdeal.com

Data Mining for Business Analytics: Concepts, Techniques


and Applications in Python eBook

https://ebookmass.com/product/data-mining-for-business-analytics-
concepts-techniques-and-applications-in-python-ebook/

testbankdeal.com
Philip Joyce

C and Python Applications


Embedding Python Code in C Programs,
SQL Methods, and Python Sockets
1st ed.
Philip Joyce
Crewe, UK

ISBN 978-1-4842-7773-7 e-ISBN 978-1-4842-7774-4


https://doi.org/10.1007/978-1-4842-7774-4

© Philip Joyce 2022

Apress Standard

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

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.

This Apress imprint is published by the registered company APress


Media, LLC part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
Introduction
The C and Python programming languages are important languages in
many computer applications. This book will demonstrate how to use
the C and Python languages to write applications in SQL. It will
demonstrate how to embed a Python program within a C program.
Finally, the reader will learn how to create Python socket programs
which can communicate with each other on different computers (these
are called “sockets”).
A basic familiarity with mathematics is assumed along with some
experience of the basics of computer programs. The first two chapters
review the basics of C and Python. The chapters following these are
grouped into SQL techniques, embedded Python, and sockets
applications. There are exercises in each chapter with answers and
suggested code at the end of the book.
Any source code or other supplementary material referenced by the
author in this book is available to readers on GitHub via the book’s
product page, located at www.apress.com/9781484277737. For more
detailed information, please visit http://www.apress.com/source-code.
Acknowledgments
Thanks to my wife, Anne, for her support, my son Michael, and my
daughter Katharine. All three have mathematics degrees. Thanks to
everyone on the Apress team who helped me with the publication of
this, my third book.
Table of Contents
Chapter 1:​Python Programming
Definition of Variables
Real (Float) Numbers
Characters
Reading in Data
Arrays
Inserting into an Array
Deleting (Removing) from an Array
Searching
Updating an Array
Appending to an Array
Strings
Lists
Reading Entries in a List
Updating a List
Deleting an Element from List
Appending to a List
Dictionaries
Creating a Dictionary
Appending to a Dictionary
Amending a Dictionary
Deleting from a Dictionary
Searching Through a Dictionary
Tuples
Creating a Tuple
Concatenating Two Tuples
Creating Nested Tuples
Creating Repeated Tuples
Converting a List or a String into a Tuple
Creating Single-Element Tuple
Reading Tuple
Searching Within a Tuple
Deleting a Tuple
Using Tuple to Create Variables
If Then Else
Loops (For and While)
For Loops
While Loops
Switches
Arithmetic Operations Using Numpy
Numpy Calculations
Mathematical Graph Functions
User-Written Functions
File Access
Regressions
Summary
Exercises
Chapter 2:​C Programming
C Program Format
Adding Two Numbers
Multiply and Divide Two Numbers
For Loops
Do While Loops
Switch Instruction
If Else
If Else If
Data Arrays
Functions
Strings
Structures
Size of Variables
Goto Command
Common Mathematical and Logical Symbols
File Access
Student Records File
Summary
Exercises
Chapter 3:​SQL in C
Review of SQL and SQLite
Creating the Database
Creating a Table
Inserting Rows
Insert a Preset Row
Inserting a User-Entered Row
Selecting Rows
Selecting a Row Preset
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Selecting All Rows
Selecting Rows by Age
Amending Rows
Deleting Rows
Summary
Exercises
Chapter 4:​SQL in Python
Review of SQL
Create a Table
Mechanism for Inserting a Row
Update a Row
Delete a Row
Read a Table
Summary
Exercises
Chapter 5:​Embedded Python
Basic Mechanism
Plot a 2D Line
Plot Two 2D Lines
Plot Trigonometric Curves
Enter Data to Plot
2D Center of Mass Plot
Histograms
Importing a Picture
Summary
Exercise
Chapter 6:​Sockets
A Closer Look at Sockets
Basic Client-Server
Server-Client Pair to Send-Receive a File
Threaded Programs
Closing Down a Threaded Server
Chat Programs
Summary
Exercise
Appendix A:​Answers to Examples
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Index
About the Author
Philip Joyce
has 28 years of experience as a software engineer, working on control
of steel production, control of oil refineries, communications software
(pre-Internet), office products (server software), and computer control
of airports. He programs in Assembler, COBOL, Coral 66, C, and C++
with SQL. He served as a mentor to new graduates in the Ferranti
Company. He obtained an MSc in computational physics (including
augmented matrix techniques and Monte Carlo techniques using
Fortran) from Salford University in 1996. He is also a chartered
physicist and a member of the Institute of Physics (member of the
Higher Education Group).
About the Technical Reviewer
Swathi Sutrave
is a self-professed tech geek. She has
been a subject matter expert for several
different programming languages,
including Python, C, and SQL, for
corporations, startups, and universities.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
P. Joyce, C and Python Applications
https://doi.org/10.1007/978-1-4842-7774-4_1

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))

Now on the command line, enter “python typ1a.py”.


And you should get the output

<class 'int'>

which is the same as our first example.


This is just demonstrating the equivalence of the two methods.
Obviously, if you want to run a program with many lines of code and possibly run it many
times, then having the code in a file is more efficient.
We can demonstrate different data types being stored in the same variable using the
following code:

a1=51
print(type(a1))

a1=51.6
print(type(a1))

a1='51'
print(type(a1))

When we run this, we get

<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.

a1='51' #assign string containing 51 to variable a1


print("a1 is",type(a1)) # print the type assigned to a1

Some simple arithmetic operations are shown in the following.


The following code is held in the file “arith1.py”:

arith1a.py

Initialize the variables v1, v2, v3, and v4 with integer values.

v1= 2
v2 = 4
v3 = 7
v4 = 8

Add v1 to v2 and store the result in v5.

v5 = v1 + v2
print(v5)

The result is

You can combine the adding with the print as follows:

print(v1+v2)

Giving the same answer:

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

v10 = v3 % v2 # the % sign means show the remainder of the


division
print(v10)
gives
3

Raise by the power 2.

v11 = v2 ** 2
print(v11)
gives
16

Raise to the power held in variable v1.


Here v2 contains 4 and v1 contains 2.

v11 = v2 ** v1
print(v11)
gives
16

Show how Python obeys the rules of BODMAS (BIDMAS).


Here v2 contains 4, v1 contains 2, v3 contains 7, and v4 contains 8.

v11 = v1 + v2 * v4 - v3 # show BODMAS


print(v11)
gives
27

Show how Python obeys the normal algebra rules.

v11 = (v1 + v2) * (v4 - v3)


print(v11)
gives
6

Real (Float) Numbers


This type of number contains a decimal point. So, for the following assignments

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'>

which means that c1 is classed as a string.


Now that we know what different types of variables we can have, we will look at how we
use them.

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()

the computer waits for the user to type in data.


So if you now enter r5, the computer stores r5 in the variable vara.
You can check this by printing the contents of vara by typing

print(vara)

which prints

r5
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
We can make this more explicit by using

print("data typed in is:-", vara)


giving
data typed in is:-r5

You can also make the entry command clearer to the user by entering

varb=input(“enter some data to be stored in varb”)

Then, again we can explicitly print out the contents

print("data typed in is:-", varb)


giving
data typed in is:-r5

You have to use int(input) to enter an integer.


Otherwise, it is a string (one or more characters), for example:

n = int(input('Enter a number: '))


you enter 4
>>> print(type(n))
<class 'int'>

# Program to check input


# type in Python

num = input ("Enter number :")


print(num)
#You could enter 5 here and it would store 5 as a string and not
as a number
>>> print(num)
5
>>> print ("type of number", type(num))
type of number <class 'str'>
>>>

#entering a float number (type 'float' before the 'input'


command)
n = float(input('Enter a number: '))
Enter a number: 3.8
>>> print(type(n))
<class 'float'>
>>> print(n )
3.8

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:

from array import *


firstintarr = array('i', [2,3,5,7,11])

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

firstfloatarr = array( 'f', [0.2,4.3,21.9,7.7])

And we can now write

varfloat1 = firstfloatarr[1]
print(varfloat1)

This will store 4.3 into varfloat1.


The array mechanism has to be imported into your program.
So at the start of each program, you need to include the code

from array import *

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)
Random documents with unrelated
content Scribd suggests to you:
In the Prosobranchiata, symmetrically paired branchiae occur only
in the Fissurellidae, Haliotidae, and Pleurotomariidae, in the former
of which two perfectly equal branchiae are situated on either side of
the back of the neck. These three families taken together form the
group known as Zygobranchiata.[268] In all other families the
asymmetry of the body has probably caused one of the branchiae,
the right (originally left), to become aborted, and consequently there
is only one branchia, the left, in the vast majority of marine
Prosobranchiata, which have been accordingly grouped as
Azygobranchiata. Even in Haliotis the right branchia is rather smaller
than the left, while the great size of the attachment muscle causes
the whole branchial cavity to become pushed over towards the left
side. In those forms which in other respects most nearly approach
the Zygobranchiata, namely, the Trochidae, Neritidae, and
Turbinidae, the branchia has two rows of filaments, one on each side
of the long axis, while in all other Prosobranchiata there is but one
row (see Fig. 79, p. 169).
Fig. 62.—Bullia laevissima
Gmel., showing
branchial siphon S; F,
F, F, foot; OP,
operculum; P, penis;
Pr, proboscis; T, T,
tentacles. (After Quoy
and Gaimard.)
In the great majority of marine Prosobranchiata the branchia is
securely concealed within a chamber or pouch (the respiratory
cavity), which is placed on the left dorsal side of the animal,
generally near the back of the neck. For breathing purposes, water
has to be conveyed into this chamber, and again expelled after it has
passed over the branchia. In the majority of the vegetable-feeding
molluscs (e.g. Littorina, Cerithium, Trochus) water is carried into the
chamber by a simple prolongation of one of the lobes or lappets of
the mantle, and makes its exit by the same way, the incoming and
outgoing currents being separated by a valve-like fringe depending
from the lobe. In the carnivorous molluscs, on the other hand, a
regular tube, the branchial siphon, which is more or less closed, has
been developed from a fold of the mantle surface, for the special
purpose of conducting water to the branchia. After performing its
purpose there, the spent water does not return through the siphon,
but is conducted towards the anus by vibratile cilia situated on the
branchiae themselves. In a large number of cases, this siphon is
protected throughout its entire length by a special prolongation of the
shell called the canal. Sometimes, as in Buccinum and Purpura, this
canal is little more than a mere notch in the ‘mouth’ of the shell, but
in many of the Muricidae (e.g. M. haustellum, tenuispina, tribulus)
the canal becomes several inches long, and is set with formidable
spines (see Fig. 164, p. 256). In Dolium and Cassis the canal is very
short, but the siphon is very long, and is reflected back over the
shell.
The presence or absence of this siphonal notch or canal forms a
fairly accurate indication of the carnivorous or vegetarian tendencies
of most marine Prosobranchiata, which have been, on this basis,
subdivided into Siphonostomata and Holostomata. But this
classification is of no particular value, and is seriously weakened by
the fact that Natica, which is markedly ‘holostomatous,’ is very
carnivorous, while Cerithium, which has a distinct siphonal notch, is
of vegetarian tendencies.
In the Zygobranchiata the water, after having aerated the blood in
the branchiae, usually escapes by a special hole or holes in the
shell, situated either at the apex (Fissurella) or along the side of the
last whorl (Haliotis). In Pleurotomaria the slit answers a similar
purpose, serving as a sluice for the ejection of the spent water, and
thus preventing the inward current from becoming polluted before it
reaches the branchiae (see Fig. 179, p. 266).
In Patella the breathing arrangements are very remarkable. In
spite of their apparent external similarity, this genus possesses no
such symmetrically paired plume-shaped branchiae as Fissurella,
but we notice a circlet of gill-lamellae, which extends completely
round the edge of the mantle. It has been shown by various
authorities that these lamellae are in no sense morphologically
related to the paired branchiae in other Mollusca, but only
correspond to them functionally. The typical paired branchiae, as has
been shown by Spengel, exist in Patella in a most rudimentary form,
being reduced to a pair of minute yellow bodies on the right and left
sides of the back of the ‘neck.’ A precisely similar abortion of the true
branchiae, and special development of a new organ to perform their
work, is shown in Phyllidia and Pleurophyllidia (see below under
Opisthobranchiata). This circlet of functional gills in Patella has
therefore little systematic value, being only developed in an unusual
position, like the eyes on the mantle in certain Pelecypoda, to supply
the place of the true organs which have fallen into disuse.
Accordingly Cuvier’s class of Cyclobranchiata, which included
Patella and Chiton, has no value, and has indeed long been
discarded. In Chiton the gills never extend completely round the
animal, but are always more or less interrupted at the head and
anus. They are the true gills, the plumes being serially repeated in
the same way as the shell plates.

Fig. 63.—Patella vulgata L., seen


from the ventral side: f, foot;
g.l, circlet of gill lamellae; m.e,
edge of the mantle; mu,
attachment muscle; sl, slits in
the same; sh, shell; v, vessel
carrying aerated blood to the
heart; v´, vessel carrying blood
from the heart; ve, small
accessory vessels.
Fig. 64.—Patella vulgata L.,
seen from the dorsal side
after the removal of the
shell and the black pigment
covering the integument;
the anterior portion of the
mantle is cut away or
turned back: a, anus; br, br,
remains of the true
branchiae (ctenidia); i,
intestine; k, k´, kidneys;
k.ap, their apertures on
each side of the anus; l,
liver; m, m, mantle; mu,
attachment muscles,
severed in removal of shell;
t, t, tentacles.
In the land Prosobranchiata (Cyclostomatidae, Cyclophoridae,
Aciculidae, Helicinidae) which, having exchanged a marine for an
aerial life, breathe air instead of water, the branchia has completely
disappeared, and breathing is conducted, as in the Pulmonata, by a
lung-cavity. In certain genera of land operculates, e.g. Pupina,
Cataulus, Pterocyclus, a slight fissure or tube in the last whorl (see
Fig. 180, p. 266) serves to introduce air into the shell, which is
perhaps otherwise closed to air by the operculum. In Aulopoma,
which has no tube, the operculum admits free circulation of air. In
certain other Cyclostomatidae the apex is truncated, and air can
enter there. De Folin closed with wax the aperture of Cycl. elegans,
and found that on placing it in a pneumatic machine, the shell gave
off air through its whole surface. On the other hand, Cylindrella and
Stenogyra decollata, on being submitted to the same test, showed
that the truncated part alone was permeable by air.
Fischer and Bouvier have made some interesting observations on
the breathing of a species of Ampullaria (insularum Orb.). The
species has, in common with all Ampullaria, two siphons, but while
the right siphon is but slightly developed, the left is very long, almost
twice as long as the shell (see Fig. 65). The animal, when under the
water, lengthens its siphon, brings the orifice to the surface, and by
alternately raising and depressing its head produces in the
pulmonary sac movements of ex- and inspiration; these are repeated
about ten or fifteen times at regular intervals of from six to eight
seconds, a method of respiration strongly resembling that of the
Cetacea. At the same time, branchial respiration takes place. If
powdered carmine is added to water, the particles are seen to enter
the branchial cavity by the siphon and pass out by the short right
siphon. Sometimes the animal remains under water for hours without
rising to the surface to inspire air. In Valvata (Fig. 66) the branchia is
very large, and projects like a leaf or fan above the shell on the left
side; on the corresponding position on the right side is a long filiform
appendage, which some have regarded as representing the other
branchia.
Fig. 65.—Ampullaria insularum
Orb.: A, breathing water;
B, breathing air; Si,
siphon; T, upper; t, lower
tentacles; X, pallial
expansion, performing the
part of excurrent siphon.
(After Fischer and Bouvier,
x ⅓.)
Opisthobranchiata.—A true branchia occurs only in the
Tectibranchiata and the Ascoglossa. It lies on the right side, and is
usually more or less external, being partly covered sometimes by the
shell (as in Umbrella, Fig. 5), sometimes by a fold of the mantle. In
the Pteropoda (which are probably derived from the Tectibranchiata),
all the Thecosomata, with the exception of Cavolinia, have no
specialised branchia, but probably respire through portions or the
whole of the integument. In the Gymnosomata an accessory
branchia has in many cases been developed at the posterior end of
the body. Pneumodermon alone has both lateral and posterior
branchiae well developed, Clione and Halopsyche are destitute of
either, while the four remaining families have one branchia,
sometimes lateral, sometimes posterior.[269]

Fig. 66.—Valvata
piscinalis Müll.: br,
branchia; fi, filament;
f.l, foot lobes. (After
Boutan.)

Fig. 67.—Doris
(Archidoris)
tuberculata L., Britain:
a, anus; br, branchiae,
surrounding the anus;
m, male organ; rh, rh,
rhinophores. × ⅔.
Fig. 68.—Pleurophyllidia
lineata Otto,
Mediterranean: a,
anus; br, secondary
branchiae; m, mouth;
s.o, sexual orifice.
Certain of the Nudibranchiata possess no special breathing
organs, and probably respire through the skin (Elysia, Limapontia,
Cenia, Phyllirrhoë). The majority, however, have developed
secondary branchiae, in the form of prominent lobes or leaf-like
processes (the cerata), which are carried upon the back, without any
means of protection. These cerata are, as a rule, of extreme beauty
and variety of form, consisting sometimes of long whip-like
tentaculae, in other cases of arborescent plumes of fern-like leafage,
in others of curious bead-like appendages of every imaginable shape
and colour. In Doris they lie at the posterior end of the body, in a sort
of rosette, which is generally capable of retraction into a chamber. In
Phyllidia and Pleurophyllidia these secondary branchiae lie, as in
Patella, on the lateral portions of the mantle.
The Scaphopoda in all probability possess neither true nor
secondary branchiae.
Pulmonata.—When we use the term ‘lung,’ it must be
remembered that this organ in the Mollusca does not correspond,
morphologically, with the spongy, cellular lung of vertebrates; it
simply performs the same functions. The ‘lung,’ in the Mollusca, is a
pouch or cavity, lined with blood-vessels which are disposed over its
vaulted surface in various patterns of network. The pulmonary sac or
cavity is therefore a better name by which to denote this organ.

Fig. 69.—Geomalacus maculosus Allm., S. Ireland: P.O, pulmonary orifice.


It seems probable, as has been already shown (pp. 18–22), that
all Pulmonata are ultimately derived from marine forms which
breathed water by means of branchiae. Thus we find intermediate
forms, such as Siphonaria, possessed of both a branchia and a
pulmonary sac, the former being evanescent, while in Gadinia and
Amphibola it has quite disappeared. In the vast majority of
Pulmonata no trace of a branchia remains; its function is performed
by a chamber, always situated at the right side of the animal, and
generally more or less anterior, admitting air by a narrow aperture
which is rhythmically opened and closed. In Arion and Geomalacus
(Fig. 69) this aperture is in the front of the right side of the ‘shield,’ in
Limax (Fig. 71) in the hinder part, in Testacella (Fig. 20) it is near the
extremity of the tail, under the spire of the shell; in Janella it is on the
middle of the right edge of the shield (Fig. 70). If a specimen of Helix
aspersa, or better, of H. pomatia, is held up to the light, the beautiful
arborescent vessels, with which the upper part of the pulmonary
chamber is furnished, can be clearly seen by looking through the
aperture as it dilates. It is only in the Auriculidae that an actual
spongy mass of lung material appears to exist. When in motion, a
Helix inspires air much more frequently than when at rest.
Temperature, too, seems to affect the number of inspirations; it
appears doubtful whether, during hibernation, a snail breathes at all.
In any case, the amount of air required to sustain life must be small.
Fig. 70.—Janella hirudo
Fisch., N. Caledonia:
G, generative orifice;
P, pulmonary orifice;
T, T, tentacles. (After
Fischer.)

Fig. 71.—Limax maximus L.: PO, pulmonary


orifice. × ⅔.
With regard to the respiration of fresh-water Pulmonata there
appears to be some difference of opinion. It is held, on the one hand,
that the Limnaeidae only respire air, making periodic visits to the
surface to procure it, and that they perish, if prevented from doing
so, by asphyxiation. If, we are told,[270] as a Limnaea is floating on
the surface of the water in a glass jar, a morsel of common salt be
dropped upon its outstretched foot, it will sink heavily to the bottom,
emitting a stream of air from its pulmonary orifice. On recovering
from the shock, it will anxiously endeavour to regain the surface, but
will have some difficulty in doing so, owing to its now much greater
specific gravity. When it succeeds, it creeps almost out of the water,
and exposes its respiratory orifice freely to the air. If the experiment
is repeated several times on the same individual, it becomes so
much weakened that it has to be taken out of the water to save its
life. Moquin-Tandon, on the other hand, is strongly of opinion[271]
that there is no absolute necessity for Limnaea to obtain air by rising
to the surface, and that, if prevented from emerging, it can obtain air
from the water. When covered in by a roof of ice, Limnaea has not
been observed to suffer any inconvenience. Moquin-Tandon kept L.
glabra and Planorbis rotundatus in good health under 20 mm. of
water for eighteen and nineteen days, and relates a case in which
Physa was kept alive under water for four days, and Planorbis for
twelve. Young specimens, both of Limnaea and Planorbis, do not
rise to the surface for a supply of air; they are hatched with the
pulmonary cavity full of water.
It is probable, therefore, that Limnaeidae are capable, on
occasion, of respiration through the skin. Some authorities are of
opinion that certain long and narrow lamellae, situated within the
pulmonary sac, are employed for the purpose of aqueous
respiration. Ancylus, which never makes periodic excursions to the
surface, perhaps respires by receiving into its pulmonary chamber
the minute quantities of oxygen given off by the vegetation on which
it feeds.
Limnaeidae taken from a great depth of water, e.g. from 130
fathoms in the lake of Geneva, have been examined by Forel.[272]
The pulmonary sac is full of water, but there is no transformation of
organs, no appearance of a branchia, to meet the changed
circumstances of their environment. Doubtless a good deal of
respiration is done by the skin; being soft and vascular, it respires
the air dissolved in the water. Forel cites cases of Limnaea living at
much shallower depths, which come to the surface once, and then
remain below for months. The oxygen of this supply must soon have
become exhausted, and the animals, discontinuing for a time the use
of the pulmonary chamber, must have respired through the skin.
Shallow-water Limnaea, according to the same authority, remain
beneath the surface during cold weather; when warm weather
returns they rise to the surface to take in a supply of air. Since the
water at great depths is always very cold, there is no need for the
Limnaea living there to rise to the surface at all.
It is a curious fact that Limnaea, which have been respiring by the
skin for the whole winter, should suddenly, on the first warm days of
summer, take to rising to the surface and breathing air. But exactly
the same phenomenon is shown in the case of Limnaea from great
depths. Placed in an aquarium, they immediately begin rising to the
surface and inspiring air; in other words, they experience
instantaneously a complete transformation of their respiratory
system.
In Onchidium, a land pulmonate which has retrogressed to an
amphibious or quasi-marine mode of life, there is no organ which
represents the pulmonary or branchial cavity, the so-called lung
being only a cavity of the kidney. Respiration is, however, conducted
by the skin as well, and by the dorsal papillae.[273]
Land Mollusca can sustain, for a considerable time, complete
deprivation of atmospheric air. Helices placed in an exhausted
receiver show no signs of being inconvenienced for about 20 hours,
and are able to survive for about two or three days. If detained under
water, they are very active for about 6 hours, then become
motionless, the body swells, owing to the water absorbed, and death
ensues in about 36 hours. Immersion for only 24 hours is generally
followed by recovery. In the latter case, the cause of death is not so
much deprivation of air as compulsory absorption of water by the
skin. The amount of water thus taken up is surprising. Spallanzani
found that a Helix which weighed 18 grammes increased in weight
by 13½ grammes after a prolonged immersion. Even slugs enclosed
in moist paper gained more than 2 grammes in the course of half an
hour. Experiment has shown that the amount of carbonic acid gas
produced by respiration stands in direct relation to the amount of
food consumed. Four pairs of snails were taken which had recently
awakened from their winter sleep and had eaten heartily, and an
equal number, under the same circumstances, which had been
prevented from eating. It was found that the first four pairs produced,
in consuming a given amount of oxygen, 11, 9, 10, and 13 parts
respectively of carbonic acid, while the second set produced, in
consuming the same amount of oxygen, only 4, 8, 7, and 9 parts of
carbonic acid.[274] Hibernating Helices, if weighed in December and
again in April, will be found to have lost weight, due to the expiration
of carbonic acid. Owing to the difficulty of experiment, opinions vary
as to the absolute temperature of snails. It appears to be established
that several snails, if placed together in a tube, raise the temperature
one or two degrees C., but as a rule, the temperature of a solitary
Helix differs very slightly from that of the surrounding air. Increased
activity, whether in respiration or feeding, is found to raise the
temperature.

Fig. 72.—Cardium edule L.: A, anal; B, branchial


siphon; F, foot. (After Möbius.)

W. H. Dall, writing of the branchia in Pelecypoda, remarks[275] that


there can be no doubt that its original form was a simple pinched-up
lamella or fold of the skin or mantle. This, elongated, becomes a
filament. Filaments united by suitable tissue, trussed, propped, and
stayed by a chitinous skeleton, result in the forms, wonderful in
number and complexity, which puzzle the student to describe, much
more to classify.

Fig. 73.—Scrobicularia piperata Gmel., in its


natural position in the sand: A, efferent or anal
siphon; B, afferent or branchial siphon. (After
Möbius.)
In Pelecypoda the branchiae are placed on each side of the body,
between the mantle and the visceral mass. They lie in a chamber
known as the branchial cavity. Leading into this cavity, and behind it,
are, as a rule, two tubes or siphons, one of which conducts water to
the branchiae, while the other carries it away after it has passed over
them. The lower is known as the branchial or afferent siphon, the
upper as the anal or efferent siphon (see Figs. 72 and 73). The
action of these siphons can readily be observed by placing a little
carmine in water, near to the siphonal apertures of an Anodonta or
Unio. In many cases (e.g. Psammobia, Tellina, Mya, genera which
burrow deeply in sand) both the siphons are exceedingly long,
sometimes considerably longer than the whole shell. In some cases
the two tubes are free throughout their entire length, in others they
become fused together before their entrance within the shell (Fig.
74). In other genera, which do not burrow (e.g. Ostrea, Pecten, Arca,
Mytilus), the siphons are rudimentary or altogether absent (Fig. 75).
Fig. 74.—Solecurtus
strigillatus L., Naples:
s.af, afferent siphon;
s.ef, efferent siphon,
the two uniting in SS
externally to the shell,
× ½.
Fig. 75.—Mytilus edulis L., attached by its
byssus (By) to a piece of wood: F, foot; S,
anal siphon, the branchial siphon being
below it and not closed. (After Möbius.)
The number and arrangement of the branchiae varies
considerably. It appears probable that the different degrees of
complication of the gill indicate degrees of specialisation in the
different groups of Pelecypoda, in other words, assuming that a
simpler form of gill precedes, in point of development, a more
complicated form, the nature of the gill may be taken as indicating
different degrees of removal from the primitive form of bivalve.
1. The simplest form of gill (Nucula, Leda, Solenomya, etc.) is that
which consists (Fig. 76, A, compare Fig. 100, p. 201) of two rows of
very short, broad, not reflected filaments, the rows being placed in
such a way that they incline at right angles to one another from a
common longitudinal axis. The filaments are not connected with one
another, nor are the two leaves of each gill united at any point.
(Protobranchiata.)
Fig. 76.—Morphology of the branchiae of Pelecypoda, seen
diagrammatically in section: A, Protobranchiata; B,
Filibranchiata; C, Eulamellibranchiata; D, Septibranchiata; e, e,
external row of filaments; i, i, internal row of filaments; e´,
external row or plate folded back; i´, internal row folded back; f,
foot; m, mantle; s, septum; v, visceral mass. (From A. Lang.)

Fig. 77.—Four gill


filaments of Mytilus,
highly magnified; cj,
ciliary junctions; f,
filament. (After
Peck.)
2. In the Anomiidae, Arcadae, Trigoniidae, and Mytilidae each gill
consists of two plates or rows of much longer filaments, which
consequently occupy a much larger space in the mantle cavity (Fig.
76, B). Unable to extend beyond the limits of the mantle, filaments
are reflected or doubled back upon one another, those of the
external plate being reflected towards the outside, those of the
internal plate towards the inside. Each separate filament is not
connected with the filament next adjacent, except by surface cilia
situated on small projections on the sides of the filaments, and
interlocking with the cilia of the adjacent filament. The two
superposed plates or leaves of the gill may or may not be united by
cords running between the two parts of a filament. (Filibranchiata.)
3. In the Pectinidae, Aviculidae, and Ostreidae a further
development takes place. The filaments of each gill are reflected in
the same way as in the Filibranchiata, but the part thus reflected may
become completely united or ‘concresce’ with the mantle on the
exterior and with the base of the foot on the interior side. The leaves
of each gill plate, which have thus become doubled (the gills being
apparently two instead of one on each side), are folded or crumpled,
and the filaments are modified at the re-entrant angles of the fold.
(Pseudolamellibranchiata.)
4. In all the remaining Pelecypoda, except class 5, in other words,
in the very large majority of families, the filaments are either
reflected, as in (3), or simple; but the process of concrescence is so
far advanced that the adjacent filaments are always intimately
connected with one another in such a way as to admit the passage
of the blood; and the leaves of each gill-plate (Fig. 76, C) are united
by cross channels in a similar way. (Eulamellibranchiata.)
5. In certain of the Anatinacea alone (Cuspidaria, Lyonsiella,
Poromya, Silenia) the gills are transformed into a more or less
muscular partition, extending from one adductor muscle to the other
(Fig. 76, D), and separating off the pallial chamber into two distinct
divisions, which communicate by means of narrow slits in the
partition. (Septibranchiata.)
Fig. 78.—Transverse section of
portion of an outer gill plate of
Anodonta, highly magnified: il,
inner lamella; il´, outer lamella;
ilj, interlamellar junctions; v,
large vertical vessels. (After
Peck.)
Thus the process of gill development in the Pelecypoda appears
to lead up from a simple to a very complex type. In its original form,
at all events in the most primitive form known to us, the gill is a
series of short filaments, quite independent of one another, strung in
two rows; then the filaments become longer and double back, while
at the same time they begin to show signs of adhesion, as yet only
superficial, to one another. In a further stage, the reflected portions
become fused to the adjacent surfaces of the foot and mantle, while
the interlamellar junctions serve to lock the two gill-plates together;
finally, the mere ciliary junction of adjacent filaments is exchanged
for intimate vascular connection, while the gill-plates as a whole
become closely fused together in a similar manner.
This theory of origin is strengthened by closer observation of the
phenomena of a single group. Taking the Septibranchiata as an
instance, we find that in Lyonsiella the branchiae unite with the
mantle in such a way as to form two large pallial chambers, the
structure of the branchiae being preserved, and their lamellae
covering the partition. A further stage is observed in Poromya.
There, a similar partition exists, but it has become muscular,
preserving, however, on each side two groups of branchial lamellae,
separated one from the other by a series of slits, which form a
communication between the two pallial chambers. A further stage

You might also like