Learn Python Programming A beginner s guide to learning the fundamentals of Python language to write efficient high quality code Romano - Own the complete ebook set now in PDF and DOCX formats
Learn Python Programming A beginner s guide to learning the fundamentals of Python language to write efficient high quality code Romano - Own the complete ebook set now in PDF and DOCX formats
com
https://textbookfull.com/product/learn-python-programming-a-
beginner-s-guide-to-learning-the-fundamentals-of-python-
language-to-write-efficient-high-quality-code-romano/
OR CLICK HERE
DOWLOAD EBOOK
https://textbookfull.com/product/learn-python-programming-second-
edition-fabrizio-romano/
textbookfull.com
https://textbookfull.com/product/python-advanced-programming-the-
guide-to-learn-pyhton-programming-marcus-richards/
textbookfull.com
https://textbookfull.com/product/python-programming-a-step-by-step-
guide-from-beginner-to-advance-second-edition-eddison/
textbookfull.com
Learn to Program with Python 3: A Step-by-Step Guide to
Programming Irv Kalb
https://textbookfull.com/product/learn-to-program-with-
python-3-a-step-by-step-guide-to-programming-irv-kalb/
textbookfull.com
https://textbookfull.com/product/go-programming-language-the-ultimate-
beginner-s-guide-to-learn-go-programming-step-by-step-3rd-edition-
john-bach/
textbookfull.com
https://textbookfull.com/product/teach-your-kids-to-code-a-parent-
friendly-guide-to-python-programming-1st-edition-bryson-payne/
textbookfull.com
https://textbookfull.com/product/learn-to-program-with-
python-3-a-step-by-step-guide-to-programming-2nd-edition-irv-kalb/
textbookfull.com
https://textbookfull.com/product/advanced-guide-to-
python-3-programming-hunt/
textbookfull.com
Learn Python Programming
Second Edition
Fabrizio Romano
BIRMINGHAM - MUMBAI
Learn Python Programming
Second Edition
Copyright © 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers
and distributors, will be held liable for any damages caused or alleged to have been caused
directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals. However,
Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78899-666-2
www.packtpub.com
To my dear dear friend and mentor, Torsten Alexander Lange.
Thank you for all the love and support.
mapt.io
Mapt is an online digital library that gives you full access to over
5,000 books and videos, as well as industry leading tools to help you
plan your personal development and advance your career. For more
information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical
eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
You'll meet the same wise and caring guide in this book. Every
chapter, every example, every explanation has been carefully thought
out, driven by a desire to impart the best and most accurate
understanding of the technology, and to do it with kindness. Fab
takes you under his wing to teach you both Python's syntax and its
best practices.
I'm also impressed with the scope of this book. Python has grown
and evolved over the years, and it now spans an enormous
ecosystem, being used for web development, routine data handling,
and ETL, and increasingly for data science. If you are new to the
Python ecosystem, it's often hard to know what to study to achieve
your goals. In this book, you will find useful examples exposing you
to many different uses of Python, which will help guide you as you
move through the breadth that Python offers.
I hope you will enjoy learning Python and become a member of our
global community. I'm proud to have been asked to write this, but
above all, I'm pleased that Fab will be your guide.
Naomi Ceder
Python Software Foundation Fellow
Contributors
About the author
Fabrizio Romano was born in Italy in 1975. He holds a master's
degree in computer science engineering from the University of
Padova. He is also a certified scrum master, Reiki master and teacher,
and a member of CNHC.
I'm grateful to all those who helped me create this book. Special thanks to Dr. Naomi Ceder
for writing the foreword to this edition, and to Heinrich Kruger and Julio Trigo for reviewing
this volume. To my friends and family, who love me and support me every day, thank you.
And to Petra Lange, for always being so lovely to me, thank you.
About the reviewers
Heinrich Kruger was born in South Africa in 1981. He obtained a
bachelor's degree with honors from the University of the
Witwatersrand in South Africa in 2005 and a master's degree in
computer science from Utrecht University in the Netherlands in 2008.
I would like to thank my parents for their love, good advice, and continuous support. I would
also like to thank all the friends I have met along the way, who enriched my life, for keeping
up my motivation, and make me progress.
Packt is searching for authors
like you
If you're interested in becoming an author for Packt, please visit
authors.packtpub.com and apply today. We have worked with thousands of
developers and tech professionals, just like you, to help them share
their insight with the global tech community. You can make a general
application, apply for a specific hot topic that we are recruiting an
author for, or submit your own idea.
Table of Contents
1. Title Page
6. Contributors
1. About the author
2. About the reviewers
3. Packt is searching for authors like you
7. Preface
1. Who this book is for
4. An extensive library
5. Software quality
6. Software integration
7. Satisfaction and enjoyment
4. What are the drawbacks?
5. Who is using Python today?
3. Numbers
1. Integers
2. Booleans
3. Real numbers
4. Complex numbers
5. Fractions and decimals
4. Immutable sequences
1. Strings and bytes
1. Encoding and decoding strings
2. Indexing and slicing strings
3. String formatting
2. Tuples
5. Mutable sequences
1. Lists
2. Byte arrays
6. Set types
7. Mapping types – dictionaries
8. The collections module
1. namedtuple
2. defaultdict
3. ChainMap
9. Enums
10. Final considerations
1. Small values caching
2. How to choose data structures
1. Positional arguments
2. Keyword arguments and default values
3. Variable positional arguments
4. Variable keyword arguments
5. Keyword-only arguments
6. Combining input parameters
7. Anonymous functions
8. Function attributes
9. Built-in functions
10. One final example
11. Documenting your code
12. Importing objects
1. Relative imports
13. Summary
5. Saving Time and Memory
1. The map, zip, and filter functions
1. map
2. zip
3. filter
2. Comprehensions
1. Nested comprehensions
2. Filtering a comprehension
3. dict comprehensions
4. set comprehensions
3. Generators
1. Generator functions
2. Going beyond next
3. The yield from expression
4. Generator expressions
4. Some performance considerations
5. Don't overdo comprehensions and generators
6. Name localization
7. Generation behavior in built-ins
8. One last example
9. Summary
6. OOP, Decorators, and Iterators
1. Decorators
1. A decorator factory
2. Object-oriented programming (OOP)
1. The simplest Python class
2. Class and object namespaces
3. Attribute shadowing
4. Me, myself, and I – using the self variable
5. Initializing an instance
1. Static methods
2. Class methods
10. Private methods and name mangling
11. The property decorator
12. Operator overloading
13. Polymorphism – a brief overview
3. Unit testing 
1. Writing a unit test
2. Mock objects and patching
3. Assertions
4. Testing a CSV generator
1. Boundaries and granularity
2. Testing the export function
3. Final considerations
2. Test-driven development
3. Exceptions
4. Profiling Python
1. When to profile?
5. Summary
2. Token generation
3. Digest comparison
4. HMAC
5. JSON Web Tokens
1. Registered claims
1. Time-related claims
2. Auth-related claims
1. Properties of a process
5. Multithreading or multiprocessing?
3. Concurrent execution in Python
1. Starting a thread
2. Starting a process
3. Stopping threads and processes
1. Stopping a process
4. Spawning multiple threads
5. Dealing with race conditions
6. A thread's local data
7. Thread and process communication
1. Thread communication
2. Sending events
2. Assertions
7. Where to find information
2. Troubleshooting guidelines
1. Using console editors
2. Where to inspect
3. Using tests to debug
4. Monitoring
3. Summary
12. GUIs and Scripts
1. First approach – scripting
1. The imports
2. Parsing arguments
4. Threading considerations
4. Summary
13. Data Science
1. IPython and Jupyter Notebook
1. Installing the required libraries
2. Using Anaconda
3. Starting a Notebook
2. Dealing with data
1. Setting up the Notebook
2. Preparing the data
3. Cleaning the data
4. Creating the DataFrame
I wanted this book to not just be about the language but about
programming. The art of programming, in fact, comprises many
aspects, and language is just one of them.
With all these goals in mind, I then had to face the hardest
challenge: take all the content I wanted to write and make it fit in the
amount of pages that were allowed. It has been tough, and sacrifices
were made.
And now, I have written the second edition of this book, and this
time, I had a little more space. So I decided to add a chapter about
IO, which was desperately needed, and I even had the opportunity to
add two more chapters, one about secrets and one about concurrent
execution. The latter is definitely the most challenging chapter in the
whole book, and its purpose is that of stimulating the reader to reach
a level where they will be able to easily digest the code in it and
understand its concepts.
I have kept all the original chapters, except for the last one that was
slightly redundant. They have all been refreshed and updated to the
latest version of Python, which is 3.7 at the time of writing.
When I look at this book, I see a much more mature product. There
are more chapters, and the content has been reorganized to better fit
the narrative, but the soul of the book is still there. The main and
most important point, empowering the reader, is still very much
intact.
I hope that this edition will be even more successful than the
previous one, and that it will help the readers become great
programmers. I hope to help them develop critical thinking, great
skills, and the ability to adapt over time, thanks to the solid
foundation they have acquired from the book.
Who this book is for
Python is the most popular introductory teaching language in the top
computer science universities in the US, so if you are new to software
development, or if you have little experience and would like to start
off on the right foot, then this language and this book are what you
need. Its amazing design and portability will help you to become
productive regardless of the environment you choose to work with.
If you have already worked with Python or any other language, this
book can still be useful to you, both as a reference to Python's
fundamentals, and for providing a wide range of considerations and
suggestions collected over two decades of experience.
Exploring the Variety of Random
Documents with Different Content
you ‘Hoch!’ when you get a bit nearer!” And I think we did. At any rate we
kept on firing at them all the time they were advancing; but they swept
ahead in such big numbers that we were forced to retire into the wood.
As soon as we got into the wood we came under very heavy machine-
gun fire from the Germans, and the bullets rained about us, driving into the
earth and into the trees and whizzing all around us everywhere. The
German shells were smashing after us, too, but were not doing much
damage at that point.
It was now that I lost a very old chum of mine, a fine chap from
Newcastle named Layden, a private. He was in the thick of the machine-
gun fire, a few paces from me, when he suddenly cried out and I knew that
he was hit. The first thing he said was, “Give me a cigarette. I know I shan’t
go on much longer.” When we asked him what the matter was he said he
was hurt. “Are you wounded?” he was asked. “Yes, I’m hit in the stomach,”
he answered—and he was, by about seventeen bullets.
The call went round for a cigarette, but nobody had one—lots of
cigarettes were sent out to the soldiers that never reached them—but poor
Layden was soon beyond the need of fags. He was delirious when our
stretcher-bearers came and took him to a barn which had been turned into a
temporary hospital. He lingered there for some time; but the last I saw of
him was on the field. I missed him badly, because we had been good chums,
and whatever we got we used to give each other half of it.
For about five hours, until two o’clock in the afternoon, that part of the
battle went on, and all the time we were holding the Germans back; then we
were reinforced by the remainder of our troops, who came across the
pontoon bridge to our assistance.
The Germans now seemed to think that they had had enough of it and
they held up white flags, and we left the shelter of the wood and went out to
capture them. I should think that there were about three hundred of the
Germans at that point who pretended to surrender by holding up the white
flag; but as soon as we were up with them their people behind fired at us—a
treacherous trick they practised very often. In spite of it all we managed to
get the best part of the prisoners safe and drove them in before us to our
own lines. When they really surrendered, and did not play the white flag
game, we used to go up and take all their rifles, bayonets and ammunition,
and throw them away out of their reach, so that they could not make a
sudden dash for them and turn on us. When we had chased a few prisoners
and had seen what the Germans meant by the white flag signal, we were
told to take no notice of it, but to keep on shooting till they put their hands
up.
A lot of the prisoners spoke English and said how glad they were to be
captured and have no more fighting to do. Some said they loved England
too much to want to fight against us, and a German said, “Long live King
George, and blow the Kaiser!” But I don’t know how many of them meant
what they said—you can’t depend on Germans.
We had plenty of talks with the German prisoners who could speak
English. Some of them who had lived in England spoke our language quite
well, and it was very interesting to hear what they had to say about us and
the French and the Belgians. They couldn’t stand the British cavalry, and
one man said, “We don’t like those Englishmen on the grey horses at all,”
meaning the Scots Greys. Several of the prisoners said they didn’t mind so
much fighting the French, because the French infantry fired too high, nor
the Russians, because they fired too low; “but,” they said, “every time the
Englishman pulls the trigger he means death.” That was a very nice
compliment to us, and there was a great deal of truth in what was said about
the British rifle fire. I can assure you that when we settled down to the work
we often enough plugged into the Germans just as if we were on
manœuvres.
At the very first—and I’m not ashamed to say it—I shook like a leaf and
fired anyhow and pretty well anywhere; but when that first awful
nervousness had passed—not to return—we went at it ding-dong all the
time and fired as steadily as if we were on the ranges. The men were
amazingly cool at the business—and as for the officers, well, they didn’t
seem to care a rap for bullets or shells or anything else, and walked about
and gave orders as if there were no such things in the world as German
soldiers.
Most of the poor beggars we took were ravenous for want of food, and
those who could speak English said they had been practically without food
for days, and we saw that they had had to make shift with the oats that the
horses were fed with. This starvation arose from the fact that a few days
earlier we had captured the German transport and left them pretty short of
food.
That rush after the Germans and bagging them was exciting work. It was
successful and everything seemed to be going very well. But there was a
nasty surprise in store for me and one which very nearly ended my career as
a fighting man. I had really a miraculous escape.
I had charge of about four prisoners, and kept them well in front of me,
so that they could not rush me. I kept them covered with my rifle all the
time, and as I had ten rounds in my magazine I knew that they wouldn’t
have a ghost of a chance if they tried any German tricks on me—I could
easily have finished the lot before they could have got at me.
As I was driving the prisoners I felt as if some one had come up and
punched me on the ear. I did not know whether I had been actually hit by
somebody or shot, but I turned my head and at once fell to the ground. I
was swiftly up again on my feet and scrambled about. I knew that I was
hurt, but the thing I mostly cared about just then was my bag of prisoners,
so I handed them over to another man, and he took them in. I then found
that I had been shot in the neck by a bullet. It had gone in at the collar of the
jacket, at the back of the neck—here’s the hole it made—and through the
neck and out here, where the scar is, just under the jaw. A narrow shave?
Yes, that’s what the doctor said—it had just missed the jugular vein. The
shot bowled me out, but it was a poor performance by the German who
fired, because he could not have been more than three hundred yards away,
and being six foot one I made a big target at that short distance. Anyway, he
missed me and I was told to go to a barn not far away which had been
turned into a hospital, bed mattresses having been placed on the floor. Here
my kit was taken off me and I was looked after at once, my kit being given
to a North Lancashire man who had lost his own and had been without one
for three days. He had been in a small battle and had had to take his choice
between dropping his kit and being caught; so he got rid of his kit and was
able to escape. When he left the barn he went into the firing line, but he
only lasted about ten minutes there. I had seen him leave
[To face p. 50.
“FROM BEHIND TREES WE KEPT UP A DESTRUCTIVE FIRE ON THE
ENEMY.” (p. 45).
[In the first four months of the war nineteen Victoria Crosses were gazetted for
valour in the field, and of these no fewer than five were awarded for the
sanguinary fighting at Le Cateau on August 26th, 1914. In his despatch dealing
with the retreat from Mons Sir John French described the 26th as “the most
critical day of all.” It was during this crisis of the battle that Corporal Frederick
William Holmes, of the 2nd Battalion The King’s Own (Yorkshire Light Infantry),
“carried a wounded man out of the trenches under heavy fire and later assisted to
drive a gun out of action by taking the place of a driver who had been wounded.”
Corporal Holmes has not only won the Victoria Cross, but he has been also
awarded the Médaille Militaire of the Legion of Honour of France. His story gives
further proof of the wondrous courage and endurance of the gallant British Army
in Belgium and in France.]
For seven years I was with the colours in the old 51st, which is now the
Yorkshire Light Infantry, then I was drafted to the Reserve; but I was called
back only a fortnight later, when the war broke out.
The regimental depôt is at Pontefract, in South Yorkshire, which some
unkind people say is the last place that God started and never finished, and
in August, having become a soldier again, after marrying and settling down
to civil life in Dublin, I found myself in a region which was almost like the
South Yorkshire coalfields. There were the same pit-heads and shale-heaps,
so that you could almost think you were in England again—but how
different from England’s calmness and security! It was around these pit-
heads and shale-heaps that some of the fiercest fighting of the earlier days
of the war took place.
We had left Dublin and reached Havre at midnight; we had been to the
fortified town of Landrecies, where the Coldstreamers were to do such
glorious things, and had got to Maroilles, where Sir Douglas Haig and the
1st Division became heavily engaged. We were at Maroilles, in billets, from
the 18th to the 21st. Billets meant almost anything, and we lived and slept
in all sorts of places as well as the trenches—but being in the open in
summer was no hardship. The fields had been harvested and we often slept
on the stacks of corn.
The people were really most kind; they gave us every mortal thing as we
marched, beer, wine, cigarettes and anything else there was.
At five o’clock on the Saturday afternoon we were billeted in a brewery,
where we stayed till Sunday noon, when, as we were having dinner, shells
were bursting and beginning things for us. We were ordered to take up a
position about two miles from Mons, and on that famous Sunday we went
into action near a railway embankment.
People by this time know all about Mons, so I will only say that after
that hard business we retired towards Le Cateau, after fighting all day on
the 24th and all the following night. After that we took up a position on
outpost and stayed on outpost all night, then, at about two in the morning,
we dropped into some trenches that we had previously occupied.
I know what Mons was and I went through the battles of the Marne and
the Aisne; but nothing I had seen could be compared for fury and horror
with the stand of the 5th Division on the 26th. It was essentially a fight by
the 5th, because that was the only division employed at Le Cateau. The
division was composed of three brigades, the 12th, 13th and 14th. My
battalion, the 2nd Yorkshire Light Infantry, was in the 13th, the other
battalions with us being the West Riding, the King’s Own Scottish
Borderers and the West Kent.
There were some coal-pit hills in front of us and the Germans advanced
over them in thousands. That was about eleven o’clock in the morning, and
the firing began in real earnest again.
The Germans by this time were full of furious hope and reckless
courage, because they believed that they had got us on the run and that it
was merely a question of hours before we were wiped out of their way.
Their blood was properly up, and so was ours, and I think we were a great
deal hotter than they were, though we were heavily outnumbered. We
hadn’t the same opinion of German soldiers that the Germans had, and as
they rushed on towards us we opened a fire from the trenches that simply
destroyed them.
Some brave deeds were done and some awful sights were seen on the top
of the coal-pits. A company of Germans were on one of the tops and an
officer and about a dozen men of the “Koylis” went round one side of the
pit and tried to get at them. Just as they reached the back of the pit the
German artillery opened fire on the lot, Germans and all—that was one of
their tricks. They would rather sacrifice some of their own men themselves
than let any of ours escape—and they lost many in settling their account
with the handful of Englishmen who had rushed behind the pit at a whole
company of Germans.
Hereabouts, at the pits, the machine-gun fire on both sides was
particularly deadly. Lieutenant Pepys, who was in charge of the machine-
gun of our section, was killed by shots from German machine-guns, and
when we went away we picked him up and carried him with us on the
machine-gun limber until we buried him outside a little village in a colliery
district.
He was a very nice gentleman and the first officer to go down. When he
fell Lieutenant N. B. Dennison, the brigade machine-gun officer, took
charge. He volunteered to take over the gun, and was either killed or
wounded. Then Lieutenant Unett, the well-known gentleman jockey,
crawled on his stomach to the first line of the trenches, with some men,
dragging a machine-gun behind them. They got this gun into the very front
of the line of the trenches, then opened fire on the Germans with disastrous
effect. Lieutenant Unett was wounded and lay in the open all the time.
This gallant deed was done between twelve noon and one o’clock, and I
was one of the few men who saw it. I am glad to be able to pay my humble
tribute to it.
There was a battery of the Royal Field Artillery on our left rear, about
800 yards behind the front line of trenches. Our gunners had such excellent
range on the Germans that the German gunners were finding them with
high explosive shell. It was mostly those shells that were dropping on them
till they got the range and killed the gunners. There were only about five
who were not either killed or wounded. The officer was wounded; but in
spite of that he carried a wounded man round the bottom of the hill, then
went back and fetched another man and repeated the journey until he had
taken every one of the five away. After that he returned, picked up a spade
and smashed the sights of the gun and made it useless. We heard some time
afterwards that he had been killed.
This brave deed was witnessed by most of us who were in the front line
of trenches.
When the German guns were got into position in front of us and the
Germans tried their hardest to blow us out of our trenches, they searched for
our artillery and, failing to discover it, they grew more determined than ever
to rout us out of the place from which we were doing deadly damage.
In spite of the heavy losses around us we held on, and all the more
stubbornly because we expected every moment that the French would come
up and reinforce us. The French were due about four o’clock, but owing to
some accident they did not arrive, and it seemed as if nothing could save us.
There was a falling off in our artillery fire, and it was clear that one of
our batteries had been put out of action. And no wonder, for the German
guns were simply raining shells upon us. The Germans at that time were
sticking to the dense formations which had been their practice since the war
began—and they hurled themselves forward in clouds towards the 37th
Field Battery.
So furiously did they rush, so vast were their numbers, and so certain
were they that they had the guns as good as captured, that they actually got
within a hundred yards of the battery.
It was at this terrible crisis that Captain Douglas Reynolds and
volunteers rushed up with two teams and limbered up two guns, and in spite
of all the German batteries and rifles did one gun was saved. This was a
wonderful escape, in view of the nearness of the German infantry and their
numbers, and for their share in the desperate affair the captain and two of
the drivers—Drane and Luke—who had volunteered, got the Victoria
Cross.
In a way we had got used to retiring, and we were not at the end of it
even now, by a good deal, for on our left the Borderers were withdrawing
and on our right the Manchesters were being forced right back; fighting
magnificently and leaving the ground littered with their dead and wounded.
The Yorkshire Light Infantry were left in the centre of the very front line
of the trenches, where we were heavily pressed. We made every mortal
effort to hold our ground, and C Company was ordered up from the second
line to reinforce us in the first.
Imagine what it meant for a company of infantry to get from one trench
to another at a time like that, to leave shelter, to rush across a space of open
ground that was literally riddled with shrapnel and rifle bullets, and in the
daytime, too, with the Germans in overwhelming force at point-blank range.
But the order had been given, and C Company obeyed. The men sprang
from their trench, they rushed across a fire-swept zone—and the handful of
them who were not shot down made a final dash and simply tumbled into
our trench and strengthened us. They had just about lost their first wind, but
were soon hard at it again with the rifle and did murderous work, if only to
get something back on account of the comrades who had fallen.
It was a help, a big help, to have C Company with us in the front trench;
but even with this reinforcement we could do nothing, and after we had
made a hot stand the order came to retire. That was about half-past four in
the afternoon.
Things had been bad before; they were almost hopeless now, for to retire
meant to show ourselves in the open and become targets for the German
infantry; but our sole chance of salvation was to hurry away—there was no
thought of surrender.
When the order was given there was only one thing to do—jump out of
the trenches and make a rush, and we did both; but as soon as we were seen
a storm of bullets struck down most of the men.
At such a time it is every man for himself, and it is hardly possible to
think of anything except your own skin. All I wanted to do was to obey
orders and get out of the trench and away from it.
I had rushed about half-a-dozen yards when I felt a curious tug at my
boot. I looked to see what was the matter and found that my foot had been
clutched by a poor chap who was wounded and was lying on the ground
unable to move.
“For God’s sake, save me!” he cried, and before I knew what was
happening I had got hold of him and slung him across my back. I can’t
pretend to tell you details of how it was all done, because I don’t clearly
remember. There was no time to think of much besides the bullets and the
fastest way of getting out of their reach. Rain was falling, not heavily, but it
was drizzling, and this made the ground greasy and pretty hard going.
I had not gone far before the poor chap complained that my equipment
hurt him and begged me to get it out of his way. The only thing to be done
was to drop the equipment altogether, so I halted and somehow got the pack
and the rest of it off, and I let my rifle go, too, for the weight of the lot, with
the weight of a man, was more than I could tackle.
I picked my man up again, and had struggled on for twenty or thirty
yards when I had to stop for a rest.
Just then I saw the major of the company, who said, “What’s the matter
with him?”
I could not speak, so I pointed to the man’s knees, which were shot with
shrapnel; then the major answered, “All right! Take him as far as you can,
and I hope you’ll get him safely out of it.”
I picked him up again and off I went, making straight over the hill at the
back of the position we had taken, so that he should be safe from the
German fire. The point I wanted to reach was about a mile away, and it was
a dreadful journey; but I managed to do it, and when I had got there, after
many rests, I started to carry my man to the nearest village, which was
some distance off.
I got to the village, but the German heavy shells were dropping so fast
that I could not stay there, and they told me to carry him into the next
village. I was pretty well worn out by this time, but I started again, and at
last with a thankful heart I reached the village and got the man into a house
where wounded men were being put.
How far did I carry him?
Well, it was calculated that the distance was three miles; but I never felt
the weight. Yes, he was quite conscious and kept on moaning and saying,
“Oh!” and telling me that if ever he got out of it he would remember me;
but I said that he mustn’t talk such nonsense—for I wanted him to stop
thanking me and to keep his spirits up.
I don’t know how long I was in getting him over the ground, for I had no
idea of time.
Having put my man in safety I left the house and began to go back to the
position, expecting to find some of the regiments to rejoin, but when I
reached the firing line there were no regiments left. They had been forced to
retire, and the ground was covered with the dead and wounded, as it was
impossible to bring all the wounded away.
There was a road at this particular point, and on reaching the top of it I
saw the Germans advancing, about 500 yards away. Between them and
myself there was a field-gun, with the horses hooked in, ready to move off;
but I saw that there was only a wounded trumpeter with it.
I rushed up to him and shouted, “What’s wrong?”
“I’m hurt,” he said. “The gun has to be got away; but there’s nobody left
to take it.”
I looked all around, and saw that there were no English gunners left—
there were only the Germans swarming up, 500 yards away and badly
wanting to get at the gun.
There was not a second to lose. “Come on,” I said, and with that I
hoisted the trumpeter into the saddle of the near wheel horse, and
clambering myself into the saddle of the lead horse we got the gun going
and made a dash up the hill.
There was only the one road, and this was so littered up and fenced
about with wire entanglements
that we could not hope to escape by it. Our only chance was by dashing at
the hill, and this we did—and a terrible business it was, because we were
forced to gallop the gun over the dead bodies of our own men—mostly
artillerymen, they were. Many of the poor chaps had crawled away from
their battery and had died on the hillside or on the road.
We carried on over the hill, and when the Germans saw what we were
doing they rained shells and bullets on us. One or two of the horses were
hit, and a bullet knocked my cap off and took a piece of skin from my head
—just here. But that didn’t hurt me much, nor did another bullet which
went through my coat. We carried on, and got over the hill, just driving
straight ahead, for we couldn’t steer, not even to avoid the dead.
I daresay the bullet that carried off my cap stunned me a bit, at any rate I
didn’t remember very much after that, for the time being; all I know is that
we galloped madly along, and dashed through two or three villages. There
was no one in the first village; but in the second I saw an old lady sitting
outside a house, with two buckets of water, from which soldiers were
drinking. She was rocking to and fro, with her head between her hands, a
pitiful sight. Shells were dropping all around and the place was a wreck.
I carried on at full stretch for about ten miles, tearing along to get to the
rear of the column. I don’t remember that I ever looked back; but I took it
that the trumpeter was still in the saddle of the wheel horse.
At last I caught up with the column; then I looked round for the
trumpeter, but he was not there, and I did not know what had become of
him. That was the first I knew of the fact that I had been driving the gun by
myself.
Willy-nilly I had become a sort of artilleryman, and from that time until
the 28th I attached myself to the guns; but on that day I rejoined what was
left of my old regiment.
I had been in charge of twelve men, but when I inquired about them I
found that only three were left—nine had been either killed or wounded,
and the rest of the battalion had suffered in proportion. That gives some
idea of the desperate nature of the fighting and the way in which the little
British army suffered during the first three days after Mons.
The officer who had seen me carrying the man off did not see me go
back, but a sergeant who knew me noticed me passing through the village
with the gun and he was the first man of my battalion that I saw. This was
Sergeant Marchant, who, for his gallantry in helping another sergeant, who
was wounded, was awarded the Distinguished Conduct Medal. In that fine
affair he was helped by Company-Sergeant-Major Bolton, and both of them
were mentioned in despatches.
Of course I never thought of saying anything about what I had done; but
I was sent for and asked if it was true, and I said I had got the man away
and helped to take the gun off, and this was confirmed by the major who
had seen me carrying the man.
For the day’s work at Le Cateau two Victoria Crosses were given to my
regiment—one to Major C. A. L. Yate, “Cal,” he was called, because of his
initials, and one to myself.
Major Yate was a very fine officer. He joined us and took command of B
Company just before we went out to the war. On this day he was in the
trenches, on our left rear, not very far from where I was. When we went into
action he had 220 men, but they caught so much of the hot fire which was
meant for the battery behind that he lost all his men except nineteen when
he was surrounded and captured. The day before this happened the major
declared that if it came to a pinch and they were surrounded he would not
surrender—and he did not surrender now. Reckless of the odds against him
he headed his nineteen men in a charge against the Germans—and when
that charge was over only three of the company could be formed up. All the
rest of B Company were either killed or wounded or taken prisoners, though
very few prisoners were taken. The major was one of them; but he was so
badly wounded that he lived only a very short time, and died as a prisoner
of war. His is one of the cases in which the Cross is given although the
winner of it is dead. Major Yate was an absolute gentleman and a great
favourite with us all. He had had a lot of experience in the Far East and at
home, and I am sure that if he had lived he would have become a general.
He was always in front, and his constant cry was “Follow me!”
From Le Cateau we got to the Valley of the Aisne and were in trenches
for ten days. At midnight on September 24th we advanced two miles
beyond the river, which we had crossed by pontoons because all the other
bridges had been blown up.
We reached a little village and stayed there in shelters underneath the
houses, where all the inhabitants slept. We stayed in one of these cellars and
went on outpost at four in the morning and came off at four next morning,
then went on again at four a.m.
We were only 250 yards from the Germans, who were in a small wood
outside the village, opposite the houses. They had snipers out and were
sniping at us all the time. We barricaded the windows of the houses and
knocked bricks out of the walls to make loopholes, and through these
loopholes we sniped the Germans, and they did their level best to pick us
off too. Every time your head was shown a dozen bullets came, and you
could not see where they came from. Two or three of our men were killed
by snipers; but there was no real chance of getting to grips, for there was
barbed wire everywhere, and nothing could be done till this was cut. Night
was the only time when the wire could be cut—and night work was both
eerie and nerve-racking.
We had “listeners” to listen for any movement by the enemy. A sentry in
peace times means a man who walks up and down, smartly dressed, but in
war time, at night, he is a listener, and in the daytime he is a “watcher”—he
can see in the daytime and hear at night. That is one of the little things
which show how greatly war changes the customs of peace.
It was outside Béthune, when we were in reserve to the rest of the
brigade, that I was wounded. We had got well into October and we were
behind trenches, with French infantry on our right. At night we advanced,
on a level with the firing line, and in the darkness we dug trenches. We were
then next to the King’s Own Scottish Borderers. We finished the trenches
before the early hours of the morning and stuck in them till five in the
afternoon, when we heard some shouts, and on looking over we saw that the
Germans were making a charge.
We opened rapid fire and the Germans answered very smartly, having
dropped down. But they were not down long, for up they sprang and with
further shouts on they came and got within three hundred yards of us. Then
we were ordered to fix bayonets and be ready to charge at any moment; but
before we started charging we rushed into another line of trenches in front
of us, and there we mixed with the Borderers.
This fight in the night was a thrilling affair, the chief guide on each side
being the flashes of the rifles, and these were incessant. The Germans were
firing rapidly at anything they could see; but there was little to see except
the tiny forks of flame. They must have heard us, however, and that, of
course, would help them. One strange thing happened when we reached the
trench, and that was that we had to wake up some of the men. In spite of the
fighting they were sleeping—but war turns everything upside down, and the
British soldier reaches a point when it takes a lot to disturb him.
Suddenly, at this crisis, I felt as if my leg had been struck by something
that vibrated, like a springboard, and I dropped down. I was dizzy, but did
not think I was hit, and I supposed that if I stayed down for a few minutes I
should be all right and able to go on. So I sat down, but quickly found that I
could not move, and on feeling my leg I discovered that it was wet and
warm, and I knew what that meant, so I took off my equipment and put it
down and began to crawl back to the trench I had left when we charged.
I crawled across a mangel-wurzel field to a house of some sort, then I
must have become unconscious, for the next thing I knew was that I was
being carried along on a stretcher.
It was only yesterday that a friend in my battalion wrote to tell me that
we were crawling pretty close together through the mangel-wurzel field. He
was shot in the arm and stopped two of the Borderers’ stretcher-bearers just
in time to have me put on a stretcher.
I had a natural walking-stick which I had cut from a vine, and of which I
was very fond. I had fastened it to my rifle and was so proud of it that I said
I would carry it through the war, if I could. My friend must have known
how I prized the vine-stick, for when he was sent home he brought it with
him, and it’s waiting for me when I leave hospital.
I also had a letter from my company officer a few days ago. He says he
missed me that night, but he could not make out what had happened. He
heard that a complete set of equipment had been found, and on learning that
I was wounded he assumed that it was mine, and that I had been carried
away and left it. He told me that on the very night I was wounded they were
relieved by the French infantry, and that he himself was hit ten days
afterwards. It was the day before I was wounded that I heard that I was
recommended for the French Military Medal, and that was as big a surprise
to me as the news that I had been given the Victoria Cross.
That equipment of mine had a tragic history. During the first day of the
Aisne I was without equipment and set to work to get some. A bugler of my
battalion had been killed by shrapnel and I was told by my officer to go and
get his equipment. “Treat him gently, poor chap,” said the officer, and you
may be sure I did. I helped myself, and thinking that the poor lad’s mother
might like a memento I brought away his “iron-rations” tin. This is riddled
with bullet-holes, just as the bugler was.
There is one thing more that I would like to say, and it is about my
birthday, which falls on September 7th. As I had left the colours and gone
into the Reserve I thought I could look forward to a fine celebration of the
anniversary. And there was a fine celebration, too, for on September 7th our
retiring before the Germans ended and we started to advance and drive
them back.
Could any British soldier want a finer birthday celebration than that?
CHAPTER VI
I went from England with the first party in the Expeditionary Force, and
after landing on the other side of the Channel, we had a march of fifty miles
to Mons, where I had my first battle.
I was in the great retirement—but I suppose you have heard enough
about that and Mons already, so I will leave it. After that beginning, I took
part in the Battle of the Marne and the Battle of the Aisne, and later on I
was shot in the thigh and bowled out.
I am only a young soldier—I am a native of Sunderland, and was born in
1891—and I have only been in the army a few months—in the old 68th, the
“Faithful Durhams,” so I think I have seen a fair lot of the big war and have
got to know what it means.
The Durhams have done splendidly and suffered terribly, and many a
chum of mine is sleeping with thousands more British soldiers on the
battlefields of France and Belgium. A great many have been wounded, and
of course there are a number of missing, mostly men, I dare say, who are
prisoners of war.
I had been at sea before joining the army, and thought I knew something
about roughing it; but even the North Sea in bad weather was nothing
compared with the hardships of the retirement from Mons, and the living
and sleeping in the trenches when the ground was sodden and deep in water.
Sometimes we were very short of food, and once for several days on end
we were almost starving, because the supplies could not get up to us, and
we had been forced to throw away a lot of our packs and things.
A good many of us had to carry a seven-pound tin of bully beef in
addition to our heavy packs and a great many rounds of ammunition. In the
fearfully hot weather we could not carry all this weight, and the tins of beef
had to go. We should have been thankful for them later on, when we ran
short and some of the beef we had with us had gone bad through the tins
getting punctured, which happened in all sorts of strange ways, including
bullet-holes and bayonet pricks. But these were things that couldn’t be
helped, and in spite of them all we kept very cheerful, and often enough,
both on the march and in the trenches and French forts, when we got to
them, we sang and joked and whistled as if there was no such thing going
on as war.
Our officers shared everything with us, and suffered just as we did,
though often worse, so that whenever we got a bit downhearted, their
example cheered us up and put us right. I don’t think there’s a man who’s
fought in this great war who won’t say the same thing about his officers.
We had so much fierce fighting when the work really began, and saw so
many strange and dreadful things, that it is not easy to say what stands out
most clearly in our minds in such a business, but one of the things I do
remember, and shall never forget, is the week or so we spent in one of the
big French forts at Lille, fighting side by side with French soldiers. I will
tell you about that later, but we did a lot before we got to Lille.
When we were on the march we had a great deal of exciting work to do
in hunting Germans. Small bodies of them were everywhere, apart from the
immense numbers of spies who were in the Lille district and elsewhere.
The French bagged a lot of spies and gave them short shrift. They hid in
all sorts of queer places—some of them got into the tall mill chimneys—but
they were routed out and shot.
We found a fair lot of Germans in houses and farms when we were on
the march. We examined these places thoroughly. When we arrived at
farmhouses and suchlike places, a non-commissioned officer, with a small
party of men would make inquiries, often with the help of French
cavalrymen who were with us and could speak English, and we always
found that threats of fearful punishment to the womenfolk had been made
by the Germans if they told us that any Germans had been seen about. But
the women told us readily enough, especially when there happened to be
any Germans in hiding—those who were too drunk to get away and had
been left behind. It didn’t take long to make these fellows prisoners, and
they rubbed their eyes a lot when they got sober and found that the British
had bagged them—though I fancy that most of them were glad to be caught
and out of the fighting.
We saw some dreadful sights in these farms and houses that we entered,
and it was no uncommon thing for us to bury the women who had been
done to death by these invaders who were worse than heathens. We had to
carry out this sad work at night, to escape the German fire, for no matter
what we were doing they went for us with rifles and machine-guns and
anything else that came handy.
Time after time on the march we saw proof of the terrible way in which
the French and Germans fought, and saw how bravely the French had
defended their country and how freely they had given their lives to get
something like even with the enemy.
The Frenchmen were naturally even more upset than the British soldiers
were at many of the sights that met us, and in the streets along which we
marched we often saw dead bodies of Frenchmen and Germans lying close
together, where they had fallen after a desperate fight on the pavements or
in the roadway. They had met and fought to the death, and it looked as if no
quarter had been given. And with all this there had been a perfectly savage
destruction of everything that the Germans could lay their hands on.
The Germans had thieved and killed wherever they had gone, led on in
the work by their officers, and little supposing, I fancy, that the day of
reckoning had come for them and that their brutal game was being spoiled.
There is no doubt that they had been taught that they were going to have a
walk over in France and were going to have a good time in Paris; but some
of them were poor enough specimens when we caught them or they
surrendered.
After the terrific battles of the Marne and the Aisne we were transferred
rather quickly to La Bassée, which is not far from Lille, and then we had to
take a share in defending Lille, in one of the big forts just outside the town.
The Germans had got up into that part of the country in very strong
force, and they were making furious efforts to smash the forts and get hold
of Lille, which had become a most important place for them.
Lille is a large manufacturing town and was very strongly defended by
forts and in other ways. These big forts, about half-a-dozen in number, form
a ring round the town and command all the countryside, or rather did, for
they have been pretty badly hammered by this time; while the town itself is
protected in other ways. Lille was also one of the big centres for French
troops, but owing to the heavy drain caused by the immense numbers of
Germans that had to be dealt with at the Aisne there were not a great many
first-rate troops left, and a good deal of the defence had to fall on the
territorials.
The particular fort where I had my strangest experiences was about a
mile from Lille, and from the outside it looked like a low hill-top, so much
so that when we were getting near it the fort seemed like a little round hill
rising from the plain.
The fort was built of immense blocks of stone, and, as far as one could
tell, great quantities of steel, so that its strength must have been enormous.
It was a romantic sort of business to get into the fort, because, first of all,
we had to pass the sentries, then some huge stone sliding doors were
opened, by a lever, I suppose, in the same way as the midway doors of a
District Railway carriage open and shut. They were very big and heavy
doors, yet they opened and shut quite easily, and when they were closed you
could hardly see a crack between them.
Past this gloomy entrance was a narrow walled slope which led into
darkness. We went down the slope into what looked like an archway and
then we got into proper blackness. It was some time before you could get
used to such darkness, but at last I saw that we had reached a large vault;
but I can’t pretend to give details, because I never had a chance of properly
making them out, and we were more concerned about the Germans than we
were about the fort.
Of course it can be easily understood that owing to the presence of great
quantities of ammunition and inflammable stores, only the dimmest lighting
was possible—in fact, there was practically no lighting at all except by little
portable electric lamps, and as for smoking, that was absolutely off.
The instant we reached the fort we were told that smoking was most
strictly forbidden, and that disobedience was punishable by death. The
French soldier is as fond as the British Tommy of his smoke, but it is a
remarkable thing that in the darkness of the fort we didn’t feel the want of
smoking, which isn’t much of a catch in the pitch darkness. As a matter of
fact I had no wish to smoke when we were in the fort, so I was never
tempted to run the risk of being shot.
Cooking, like smoking, was out of the question, for you can no more
smoke with safety in a magazine like that than you can in a coal-mine—a
spark is enough to do tremendous mischief, let alone a fire; so our rations
had to be brought to us by the Army Service Corps, though they, with their
carts, were a long way off.
The A.S.C. chaps were splendid all through, and the men in the fighting
line owe a lot to them.
In this black dungeon, with such cunning Germans about, a sentry’s
challenge was a good deal more than a formality; but it nearly became one
when the welcome commissariat man arrived. But for his coming we should
have had to fall back on our emergency rations. These were good, of their
kind, but they can’t compare with the best efforts of the A.S.C.
But I’m getting off the track a bit. In the side of the vault, or cavern,
there was a low, shallow dug-out which was meant to hold a rifleman lying
at full stretch. This was something like a small cubicle in size and shape,
and to enter it in the darkness was a proper problem. After a try or two,
however, you got into the way of stumbling comfortably into it. By
crouching and creeping, and using your hands and knees, you could secure
a position from which it was fairly easy to draw yourself up into the dug-
out. I dwell on this because I think it is important, seeing that four of us
took two-hour watches throughout the twenty-four hours, so that getting to
and from such a dug-out becomes an event in your daily life.
At one end of the dug-out was a loophole for a rifle or a maxim-gun, and
here we patiently waited for those pests, the snipers. These German potters
gave us no rest; but many a German who thought he was well hidden got
the finishing touch from one of our loopholes.
This was thrilling fighting, especially when things became hot, and we
manned all the loopholes in the fort, to the number of four, and at a pinch
we could use two maxims at each. There were fourteen of us in the fort
altogether, four officers and ten men. The orders, being in French, sounded
very strange at first, but to my surprise, I soon fell into the way of
understanding what was said around me, certainly so far as ordinary little
things were concerned. I shall never forget the French for water so long as I
remember the thirst I had in the black depths of the fort.
The life in the fort was one of the strangest parts of the whole of the
fighting. It was queer enough to be in France, fighting with the French, but
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com