Download ebooks file Object-Oriented Python 1st Edition Irv Kalb all chapters
Download ebooks file Object-Oriented Python 1st Edition Irv Kalb all chapters
com
https://ebookmeta.com/product/object-oriented-python-1st-
edition-irv-kalb/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmeta.com/product/object-oriented-python-1st-edition-irv-
kalb/
ebookmeta.com
https://ebookmeta.com/product/object-oriented-python-master-oop-by-
building-games-and-guis-1st-edition-irv-kalb/
ebookmeta.com
https://ebookmeta.com/product/the-world-series-allan-morey/
ebookmeta.com
Monkey King Volume 11 Fight to the Death 1st Edition Wei
Dong Chen Chao Peng
https://ebookmeta.com/product/monkey-king-volume-11-fight-to-the-
death-1st-edition-wei-dong-chen-chao-peng/
ebookmeta.com
https://ebookmeta.com/product/tribe-master-3-a-fantasy-harem-
adventure-1st-edition-noah-layton/
ebookmeta.com
https://ebookmeta.com/product/introducing-translation-studies-
theories-and-applications-5th-edition-jeremy-munday/
ebookmeta.com
https://ebookmeta.com/product/framing-the-sexual-subject-the-politics-
of-gender-sexuality-and-power-richard-parker-editor/
ebookmeta.com
Global Politics A New Introduction 3rd Edition Jenny
Edkins Editor Maja Zehfuss Editor
https://ebookmeta.com/product/global-politics-a-new-introduction-3rd-
edition-jenny-edkins-editor-maja-zehfuss-editor/
ebookmeta.com
CONTENTS IN DETAIL
TITLE PAGE
COPYRIGHT
DEDICATION
ACKNOWLEDGMENTS
INTRODUCTION
Who Is This Book For?
Python Version(s) and Installation
How Will I Explain OOP?
What’s in the Book
Development Environments
Widgets and Example Games
CHAPTER 8: ENCAPSULATION
Encapsulation with Functions
Encapsulation with Objects
Objects Own Their Data
Interpretations of Encapsulation
Direct Access and Why You Should Avoid It
Strict Interpretation with Getters and Setters
Safe Direct Access
Making Instance Variables More Private
Implicitly Private
More Explicitly Private
Decorators and @property
Encapsulation in pygwidgets Classes
A Story from the Real World
Abstraction
Summary
CHAPTER 9: POLYMORPHISM
Sending Messages to Real-World Objects
A Classic Example of Polymorphism in Programming
Example Using Pygame Shapes
The Square Shape Class
The Circle and Triangle Shape Classes
The Main Program Creating Shapes
Extending a Pattern
pygwidgets Exhibits Polymorphism
Polymorphism for Operators
Magic Methods
Comparison Operator Magic Methods
A Rectangle Class with Magic Methods
Main Program Using Magic Methods
Math Operator Magic Methods
Vector Example
Creating a String Representation of Values in an Object
A Fraction Class with Magic Methods
Summary
INDEX
OBJECT-ORIENTED PYTHON
by Irv Kalb
Object-Oriented Python. Copyright © 2022 by Irv Kalb.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information storage or
retrieval system, without the prior written permission of the copyright owner and the publisher.
First printing
25 24 23 22 21 1 2 3 4 5 6 7 8 9
ISBN-13: 978-1-7185-0206-2 (print)
ISBN-13: 978-1-7185-0207-9 (ebook)
Publisher: William Pollock
Managing Editor: Jill Franklin
Production Manager: Rachel Monaghan
Production Editor: Kate Kaminski
Developmental Editor: Liz Chadwick
Cover Illustrator: James L. Barry
Interior Design: Octopod Studios
Technical Reviewer: Monte Davidoff
Copyeditor: Rachel Head
Compositor: Maureen Forys, Happenstance Type-O-Rama
Proofreader: Paula L. Fleming
Indexer: Valerie Haynes Perry
The following images are reproduced with permission:
Figure 2-1, photo by David Benbennick, printed under the Creative Commons Attribution-Share
Alike 3.0 Unported license, https://creativecommons.org/licenses/by-sa/3.0/deed.en.
For information on book distributors or translations, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900; info@nostarch.com
www.nostarch.com
Library of Congress Cataloging-in-Publication Data
Names: Kalb, Irv, author.
Title: Object-oriented Python: master OOP by building games and GUIs / Irv Kalb.
Description: San Francisco : No Starch Press, [2021] | Includes index. |
Identifiers: LCCN 2021044174 (print) | LCCN 2021044175 (ebook) | ISBN
9781718502062 (print) | ISBN 9781718502079 (ebook)
Subjects: LCSH: Object-oriented programming (Computer science) | Python
(Computer program language)
Classification: LCC QA76.64 .K3563 2021 (print) | LCC QA76.64 (ebook) |
DDC 005.1/17--dc23
LC record available at https://lccn.loc.gov/2021044174
LC ebook record available at https://lccn.loc.gov/2021044175
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc.
Other product and company names mentioned herein may be the trademarks of their respective
owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are
using the names only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The information in this book is distributed on an “As Is” basis, without warranty. While every
precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc.
shall have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in it.
Other documents randomly have
different content
“Sir,” she said to the painter, “I can only offer you a lock of hair.”
And taking the gaoler’s scissors, she cut a lock of the wonderful
hair.
A priest coming, she said, “I thank those who have been kind
enough to send you, but I do not require your services. The blood I
have spilt, and my own, which I am about to shed, are the only
sacrifices I can offer the Eternal.”
The executioner now cut off her hair, and flung over her head the
red garment.
“This,” she said, “is the toilette of death, arranged by somewhat
rude hands, but it leads to immortality.”
As she stepped upon the cart, such as carried all those
condemned to death to the place of execution, a violent storm burst
over Paris. Women danced about the death-cart, uttering
imprecations; hers was the only calm face to be seen. Strangely
enough, the rain wetting the red flannel—her only covering to the
waist—it clung to her skin, and betrayed her to be exquisitely
formed, especially as her hands were so tied behind her that she
was forced to hold herself upright.
As she neared the scaffold, the sun appeared, and the gold
threads in her hair shone out magnificently.
The leaders of the rebellion, Danton, Robespierre, Camille
Desmoulins, standing at a window, saw her pass. She had preserved
them from Marat, but, at the same time, she had shown how a
tyrant could be slain. She saved their lives by her act; but she
taught, also, how they might be taken.
One Adam Lux, a German, was hopelessly stricken by love as she
passed along. He followed to the scaffold’s feet, asking to die with
her.
Reaching the scaffold, she turned pale, and, for one moment,
shrank; but the next, recovering herself, ascended the steps as
rapidly as her long red dress and pinioned arms would allow.
When the executioner pulled down her dress, that her neck might
be bare, she was for the last time outraged while living. She placed
herself upon the plank, and, the next moment, her head fell.
Legros, a miserable scaffold-dog, took up the head by the
remaining hair, and struck at the cheeks. It is said the skin grew
scarlet, as though the modesty of Charlotte Corday outlasted her
life.
Did her face change color? Some hold that the head has
consciousness and power after being severed from the body, and
that it can see and hear. Nay, it was urged during the Revolution that
the passion of the heads remained, because the interior of the
wicker baskets in which the heads were carried away were often
found to be gnawed, as though the teeth of the heads gnashed after
separation from the body. For my part, I believe that this gnawing
was effected by rats, which at that time, even more than now,
overran Paris.
Such was the death of Marat—of his murderer, whom we cannot
praise. But who can blame her? Assuredly her death was necessary
to purge her of assassination, to some extent.
Adam Lux, wild with love, published a defence of Charlotte Corday.
He was seized, and, three days afterwards, died by the very knife
which destroyed her life.
Chénier, the patriotic poet, sang her heroism. He was soon
arrested, and therefore beheaded.
But what good had Charlotte Corday done?
She had strengthened the love of the people for desperate
measures; she had made a martyr of their most foul leader. She
gave a dignity to those who advocated the scaffold. The liberal
twenty-two knew that this last act annihilated them.
C H A P T E R LV I I I .
MARIE A N TO I N E TT E .
“I write to you, my sister,” she begins, “for the last time. I have
been condemned, not to an ignominious death—that only awaits
criminals—but to go and rejoin your brother. Innocent as he, I hope
to show such firmness as the King’s in his last moments. I grieve
bitterly at leaving my poor children. You know that I lived but for
them and you—you who, in your love, have sacrificed all for us. I
learnt, at my trial, that you are separated from my little girl. In what
a position I leave you! I dare not write to her; they would not give
her my letter, and, indeed, I do not know that you will receive this.”
The twenty-two had literally been under the control of the police,
though not arrested, since May 31st. But as events progressed, their
destruction became almost necessary to the safety of those
members of the Convention, who, obtaining power wholly through
the will of the more violent, could only retain it by a perfect
recognition of the will of those who had given them the victory.
The twenty-two were therefore seized, and placed in a building
converted from a convent into a prison, and here they made full
preparations to die.
To this day, the walls of this place may be seen covered with
mementoes of the prison-days of the victims of the Revolution. They
are chiefly short verses, written in blood, the purple hues of which
many of the inscriptions still retain.
A few days after the Queen’s day of peace arrived, their trial
commenced.
Of what were they accused?
Really, nothing; but they were in the way, and a threatening
division of the masses insisted upon their death.
After four days’ mockery of justice, the twenty-two were declared
guilty of having conspired against the unity and indivisibility of the
republic, and the whole were condemned to die.
A cry of horror burst from the condemned, for many of them could
not believe that innocent men could be sent to the scaffold.
Valasé, one of the youngest, slipped from his seat to the floor.
“What, Valasé! art losing courage now?” cried his friend Brissot,
upholding him.
“No; I am dying!” returned Valasé; and his fingers quivered about
the handle of the poniard with which he had taken his own life.
Silent horror for a moment prevailed; the Girondists blushed and
bowed their heads before their dead companion, who had given
them an example of fearlessness in meeting death.
Only one, named Boileau, showed cowardice. He cast his hat into
the air and screamed, “I don’t belong to these men! I am a Jacobin!”
But instead of pity he only gained contempt.
And now a cry was heard; it came from Camille Desmoulins: “Let
me fly,” he cried; “it is my book which has killed them!”
But the crowd seized Desmoulins, and forced him to remain.
The twenty-two came down from the high seats upon which they
had heard their trial and sentence, and for a moment stood round
the dead body of their friend, who had shown them how to die.
Almost simultaneously they raised their hands and cried, “Innocent!
Long live the republic!”
Then they cast all the money they had with them amongst the
crowding, storming people, who greedily seized it. This was done,
not to excite the mob to revolt, but with the thought that, their
death at hand, they had no farther need of wealth.
There was something strangely classic and Roman-like in their
death. They left the hall singing loudly the celebrated hymn, the
“Marseillaise;” and in reference to their death, they sang with
amazing power the celebrated two lines,
“March on, march on! O children of the land,
The day, the hour of glory, is at hand!”
This terrible hymn they were still singing as they entered their
prison. It was now late in the evening, and they were to suffer on
the following morning.
The tribunal had decreed that the yet warm corpse of Valasé
should be carried back to prison, conveyed in the same cart with his
accomplices to the scaffold, and interred with their bodies. The only
sentence, perhaps, which punished the dead.
Four men-at-arms carried the body upon a litter, and thus the
procession reached the prison.
The twenty-two were to pass the night in the same room, the
corpse in one corner. The twenty-one—even Boileau, who repented
of his momentary cowardice—came, one by one, and kissed the
dead man’s hand, then covered his face, saying, “To-morrow,
brother!”
One Bailleul, a Girondist and a Conventionist, but who had
escaped the proscription, yet had not left Paris, had promised that,
after the trial, he would prepare and send to the prison, either a
triumphant or a funereal supper, according to the sentence.
The promise was kept. Upon the oaken table, stretching the
length of their dungeon was set out a supper, royal in its
magnificence. Every luxury to be obtained, every delicate wine with
a name, filled those portions of the table not covered by a wealth of
flowers and great clusters of brilliantly burning wax candles.
To one Abbé Lambert, who lived fifty years after that night, we
owe all we have learnt concerning that final meal. This minister was
waiting to offer consolation to the condemned as they passed to the
scaffold.
The supper lasted from midnight until the dawn of day—at the
end of October, about half-past five. It was the feast of their
marriage with death. No sign was given of their approaching end. All
ate with sobriety, but with appetite; and it was only when the fruit
and wine alone remained on the table that the conversation became
excited and powerful.
Many, especially the younger men, who did not leave families
behind them, were very gay and witty. They had done no great
wrong, and were sacrificed to duty, therefore they met death with
cheerful faces.
With solemn break of day, the conversation became graver.
Brissot cried, “now that we, the honest men amongst those who
govern, are about to die, what will become of the republic? How
much blood will it require to wash away the memory of ours?”
“Friends,” cried Vergniaud, “we have killed the tree by over-
pruning it. It was aged—Robespierre cuts it down. Will he be more
fortunate than ourselves? No; the land of France is now too weak for
honest growth. The people play with laws as children with toys; they
are too weak to govern themselves; and they will return to their
kings as children to their toys, after they are tired of having thrown
them away. We thought ourselves at Rome; we were in Paris. But, in
dying, let us leave to the whole of France—the strength of hope.
Some day—some great day—she will be able to govern herself.”
At ten o’clock the executioners arrived to prepare the victims for
the scaffold. Gensomé, picking up a lock of the black, brilliant hair
cut from his head, gave it to Abbé Lambert, and begged him to carry
it to his wife. “Tell her,” he said, “it is all I can send, and that I die
thinking of her.”
Vergniaud drew his watch from his pocket, scratched his initials
and the date in it with a pin, and sent it by the hands of one of the
executioners’ assistants to a young girl whom he loved deeply, and
whom it is said he intended to marry.
Every one sent a something to some one or more in memory of
himself, and it is pleasant to be able to state that every message and
remembrance were faithfully delivered.
When the last lock of hair had fallen, the victims were marshalled,
and they were led out to the carts waiting to receive them.
They sang the “Marseillaise” to the scaffold—they sang it when
they reached it, the song growing fainter and fainter as each head
fell; and the hymn only ceased, as the last head fell—that of their
leader, Vergniaud.
The dead body of their friend was carried with them.
Such was the end of the founders of the French republic.
With them the brightness, beauty, youth, wit, frankness of the
Convention passed away, and their places were filled by sullen,
threatening men.
CHAPTER LXI.
THE RED FLAG.
The first to fall was the Duc of Orleans (father of Louis Philippe,
King of the French). He had done nothing against the interests of
the republic, but his birth was a crime, and his death was decided
on.
The Prince and his sons were at table when the fatal indictment
arrived.
“So much the better,” said he. “This must end one way or the
other. Kiss me, children. And I wonder of what they accuse me?” he
said, opening the paper. “The scoundrels!” he added; “they accuse
me of nothing. Come, boys, eat; for this summons is indeed good
news.”
He was taken to Paris, where, at this time, no man of mark, being
put upon his trial, escaped the guillotine.
The one plausible accusation brought against Orleans must have
compressed his heart.
“Did you not vote the King’s death in the hope of succeeding to his
throne?”
“No; I obeyed my heart and my conscience.”
He heard his sentence calmly, despite the fact of his cowardice in
his early years; and he replied sarcastically to his judges, “Since you
were determined to condemn me, you should have found better
pretexts than you have; for, as it is, you will deceive no man into
believing that you think me guilty. I am in the way. And you too,” he
said, turning to a once Marquis d’Autonelle, an old friend,—“you to
condemn me! Finally,” he continued, “since I am to die, I demand
not to be left in gaol a whole night, but to be at once taken to the
block.”
This desire was not complied with. Returning to the gaol, his rage
was terrible.
The Abbé Lambert approached and said, “Citizen Equality, will you
accept my assistance, or, at least, the offer of my condolence?”
“Who are you?”
“The Vicar-General of the Bishop of Paris. If you will not accept my
religious help, can I be of any service to you after your death? Have
you messages to send?”
“No; I can die without help, and like a good citizen.”
He went to the place of execution at three, accompanied by three
others.
Reaching the scaffold, he looked at the knife calmly; and the
executioner offering to remove his boots, he said, “You will do it
more easily afterwards.”
He was dressed very beautifully for his death, and he died without
fear. He had followed the Revolution blindly—had thrown away
fortune, name, reputation, in its cause, and it destroyed him simply
because he had belonged to royalty.
Terror was rapidly reddening all the land.
The guillotine was not quick enough, and squads of soldiers shot
down the condemned.
Such sentences as the following, were accepted as truths:—
“The time is come when the prophecy shall be fulfilled. The
wealthy shall be despoiled, and the poor shall be enriched.
“If the people want bread, let them profit by the sight of their
misery, to seize on the possessions of the wealthy.
“Do you seek a word which furnishes all you need?—die, or cause
others to die.”
The great Terror began at Lyons.
“The great day of vengeance has arrived,” cried one Cholier. “Five
hundred men amongst us deserve to share the fate of the tyrant. I
will give you the list—be it your part to strike!”
He then seized a crucifix, dashed it upon the ground, and
trampled upon it.
Here is another theory which was applauded:—
“Any man can be an executioner—it is the guillotine which really
takes life.”
This Cholier, who had trampled upon the crucifix, clung to it when
condemned to the death he was always seeking for others. The knife
was blunt, and five times it was raised before the head fell. “Quick—
quick!” the wretch cried, when it was raised for the fifth time.
Some time after, when the Terror was rising to its height, Cholier
was looked upon as a martyr; his body was burnt, and the ashes
placed in an urn, were carried triumphantly through the streets, and
placed upon an altar of patriotism raised to him.
The altar in question was soon thrown down.
But only after the Terror ended.
With Cholier’s after-death triumph, the “moderates” began to fall.
Ten of the municipals of Lyons (the place of Cholier’s exploits) were
beheaded in one day, and a mine was exploded which destroyed the
finest parts of the city.
Lyons was almost annihilated. At a cost of half a million of money
(English), houses worth twelve millions were destroyed. Why?
France was mad. So hurriedly was this destruction effected, that
hundreds of the workmen themselves were buried in the ruins.
Life, however, was cheap.
Rags only were to be seen—a decent dress was equivalent to
condemnation. The city was dead but for the thunder of fallen
houses, the roar of cannon and the rattle of musketry mowing down
suspected people, and the shrill cry of the ragged as they marked
another head fall beneath the guillotine knife. It was now looked
upon as a distinction, and reserved only for important people.
An entire generation was destroyed in Lyons alone. Great houses
were unowned—for their owners were dead. Castles, churches,
factories, work-shops, were closed, for their heads had all passed
under the guillotine.
Starvation increased, for the land lay a-dying.
The guillotine was getting old and worn-out at Lyons.
One morning, sixty-four are marched out to death. They are
bound, and ranged in a line before an open trench. Three pieces of
cannon, loaded with bullets, sweep the ranks. Not half are touched.
“Forward!” is the word given to the dragoons, who hack and shoot
down the victims. This lasts two whole hours.
Nine hundred and thirty executioners, in the shape of an entire
regiment, were to send their victims, marshalled in a row, into
eternity at the same moment. At the order “Fire!” four bullets struck
at the life of the victims, all of whom are tied to a rope stretched
from tree to tree.
Strange—when the smoke arose, only half were found dead. The
rest remained either wounded or untouched. The unscathed stared
in horror; the wounded screamed to be despatched.
The soldiers could not fire again. Some of the prisoners had freed
themselves, and were escaping. The dragoons were ordered forward
to cut them down. The victims were killed piece-meal. One man, a
mayor of his town, reached the river, but there his bleeding hand
betrayed him, and he was cast into the river.
The soldiers protested against the use to which they were put.
The massacres lasted until night-fall. Yet when the grave-diggers
came next morning, some hearts still beat. The sextons put the
martyrs out of their misery at once by blows on the head with their
pickaxes.
“We are purging the land,” wrote Collet d’Herbois to the
Convention.
Every day twenty-two were regularly shot. By this time, the fear of
life rendered death sweet. Girls, men, children, prayed that they
might be shot with their parents. Sometimes they permitted this,
and little boys and girls were shot, holding their father’s hands.
Women who were seen to shed tears at executions, were shot.
Mourning was prohibited under pain of death.
One lad of fourteen, says, “Quick—quick! You have killed papa! I
want to overtake him!”
One De Rochefort[2] was accompanied by a son to the butchering-
ground, whither he went with three relatives. The men fell—the boy,
aged fifteen, remained standing.
The executioner hesitated—the people murmured.
“God save the King!” cried De Rochefort.
A moment—a report—he fell, shattered to death.
A lovely girl, fourteen, is brought before the judge for refusing to
wear the national cockade.
“Why do you refuse to wear it?” asks the judge.
“Because you do!” replies the child.
Her beauty, rather than justice, pleading for her, a sign was made
that a wreath should be put in her hair, the emblem of liberation.
She cast it upon the ground. She died.
A man came to the Hall of Justice.
“You have slain my father, my brothers, my wife—kill me. My
religion forbids me to destroy myself. In mercy, kill me.”
In mercy—they killed him.
A woman, who had fought bravely in the earlier and fairer time of
the Revolution, was carried to the scaffold, though about to become
a mother. She did not fear death—she pleaded for the other life.
She was laughed at—hooted—and so died.
A girl of seventeen, and much resembling Charlotte Corday, was
accused of having served as an artillerist in the trenches of the
forces opposed to the national forces.
“What is your name?”
“Mary; the name of the mother of the God for whom I am about
to die.”
“Your age?”
“Seventeen; the age of Charlotte Corday.”
“How!—at seventeen, fight against your country?”
“I fought to save it.”
“Citizen—we, your judges, admire your courage. What would you
do with your life if we gave it you?”
“Use it to kill you!”
She ascended the scaffold, alarmed at the crowd of people—
fearless of death. She refused the executioner’s help—cried twice,
“God save the King!”—and lay down to die.
After her death, the executioner found amongst her clothes a note
written in blood. It was from her lover, who had been shot some
days before.
The lovers were only separated by a few days. Their history
touched the people, but the people of that day did not know how to
pardon.
These awful executions were at last arrested, not because the
victims were exhausted, but because the soldiers threw down their