PDF Fluent Python, 2nd Edition Luciano Ramalho Download
PDF Fluent Python, 2nd Edition Luciano Ramalho Download
com
OR CLICK BUTTON
DOWLOAD NOW
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://ebookmeta.com/product/fluent-python-2nd-edition-luciano-
ramalho/
https://ebookmeta.com/product/fluent-python-2nd-edition-luciano-
ramalho-2/
https://ebookmeta.com/product/fluent-python-2nd-edition-luciano-
ramalho-3/
https://ebookmeta.com/product/fluent-python-clear-concise-and-
effective-programming-12th-early-release-2nd-luciano-ramalho/
Cambridge IGCSE and O Level History Workbook 2C - Depth
Study: the United States, 1919-41 2nd Edition Benjamin
Harrison
https://ebookmeta.com/product/cambridge-igcse-and-o-level-
history-workbook-2c-depth-study-the-united-states-1919-41-2nd-
edition-benjamin-harrison/
https://ebookmeta.com/product/fluent-react-5th-early-release-1st-
edition-tejas-kumar/
https://ebookmeta.com/product/devops-in-python-infrastructure-as-
python-2nd-edition-moshe-zadka/
https://ebookmeta.com/product/devops-in-python-infrastructure-as-
python-2nd-edition-moshe-zadka-2/
https://ebookmeta.com/product/tourism-in-natural-and-
agricultural-ecosystems-in-the-eighteenth-and-nineteenth-
centuries-1st-edition-martino-lorenzo-maffi-fagnani-luciano-
Fluent Python
SECOND EDITION
Luciano Ramalho
Fluent Python
by Luciano Ramalho
Copyright © 2022 Luciano Ramalho. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North,
Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales
promotional use. Online editions are also available for most titles
(http://oreilly.com). For more information, contact our
corporate/institutional sales department: 800-998-9938 or
[email protected].
Part V, “Metaprogramming”
This part starts with a review of techniques for building classes
with attributes created dynamically to handle semi-structured
data, such as JSON datasets. Next, we cover the familiar
properties mechanism, before diving into how object attribute
access works at a lower level in Python using descriptors. The
relationship among functions, methods, and descriptors is
explained. Throughout Part V, the step-by-step implementation of
a field validation library uncovers subtle issues that lead to the
advanced tools of the final chapter: class decorators and
metaclasses.
Hands-On Approach
Often we’ll use the interactive Python console to explore the
language and libraries. I feel it is important to emphasize the power
of this learning tool, particularly for those readers who’ve had more
experience with static, compiled languages that don’t provide a
read-eval-print loop (REPL).
One of the standard Python testing packages, doctest, works by
simulating console sessions and verifying that the expressions
evaluate to the responses shown. I used doctest to check most of
the code in this book, including the console listings. You don’t need
to use or even know about doctest to follow along: the key feature
of doctests is that they look like transcripts of interactive Python
console sessions, so you can easily try out the demonstrations
yourself.
Sometimes I will explain what we want to accomplish by showing a
doctest before the code that makes it pass. Firmly establishing what
is to be done before thinking about how to do it helps focus our
coding effort. Writing tests first is the basis of test-driven
development (TDD), and I’ve also found it helpful when teaching. If
you are unfamiliar with doctest, take a look at its documentation
and this book’s example code repository.
I also wrote unit tests for some of the larger examples using pytest
—which I find easier to use and more powerful than the unittest
module in the standard library. You’ll find that you can verify the
correctness of most of the code in the book by typing python3 -m
doctest example_script.py or pytest in the command shell
of your OS. The pytest.ini configuration at the root of the example
code repository ensures that doctests are collected and executed by
the pytest command.
Constant width
Used for program listings, as well as within paragraphs to refer to
program elements such as variable or function names, databases,
data types, environment variables, statements, and keywords.
Note that when a line break falls within a constant_width
term, a hyphen is not added—it could be misunderstood as part
of the term.
TIP
This element signifies a tip or suggestion.
NOTE
This element signifies a general note.
WARNING
This element indicates a warning or caution.
The Koreans hold rice, their chief cereal, in peculiar honour. They
state that it originated in Ha-ram, in China, at a period now involved
in much fable and mystery—2838 b.c. to 2698 b.c. The name, Syang-
nong-si, itself means Marvellous Agriculture. The name was
doubtless given at a later time. The first rice was brought to Korea
by Ki-ja in 1122 b.c. together with barley and other cereals. Before
that time the only grain raised in Korea was millet. There are three
kinds of rice in Korea, with a variety of sub-species. First, that which
is grown in the ordinary paddy-fields. This is called specifically tap-
kok, or paddy-field rice. It is used almost exclusively to make pap,
the ordinary boiled rice. Then we have chun-kok or field-rice. This is
so-called upland rice. It is drier than the paddy-field rice, and is used
largely in making rice flour and in brewing beer. The third kind is
grown exclusively on the slopes of mountains, and is a wild rice. It is
smaller and harder than the other kinds; for this reason it is used to
provision garrisons. It will withstand the weather. Under favourable
circumstances, lowland rice will keep five years, but the mountain
rice will remain perfectly sound for quite ten years.
Next in importance to rice come the different kinds of pulse, under
which heading is included all the leguminous plants, the bean and
the pea family. That Korea is well provided with this valuable and
nutritious form of food will be seen from the fact that there are
thirteen species of round beans, two kinds of long bean, and five
varieties of mixed bean. Of all these numerous assortments, the
“horse-bean” is by far the most common. It is the bean which forms
such a large part of the exports of Korea. It is supposed by Koreans
to have originated in North-Western China, and derives its name
from the fact that it is used very largely for fodder. One variety only
may be regarded as indigenous—the black-bean—and it is found
nowhere else in Eastern Asia. Of the rest, the origin is doubtful. The
horse-bean grows in greatest abundance in Kyöng-syang Province
and on the island of Quelpart, though of course it is common all over
the country. The black-bean flourishes best in Chyöl-la Province. The
green-bean, oil-bean, and white-cap bean flourish in Kyöng-keui
Province. The yellow bean is found in Hwang-hai Province; the South
River bean appears in Chyung-chyöng Province; the grandfather-
bean (so called because of its wrinkles) grows anywhere, but not in
large quantities. The brown-bean and chestnut-bean come from
Kang-won Province.
It would be difficult to over-estimate the importance of these
different species of pulse to the Korean. They furnish the oily and
nitrogenous elements which are lacking in rice. As a diet they are
strengthening, the nutritious properties of the soil imparting a tone
to the system. Preparations of beans are as numerous as the dishes
made from flour; it is impossible to enumerate them. Upon an
average, the Koreans eat about one-sixth as much pulse as rice. The
price of beans is one-half that of rice; the price of either article is
liable to variations. There are varieties which cost nearly as much as
rice.
The common name for barley is po-ri; in poetical parlance the
Koreans call barley The Fifth Moon of Autumn, because it is then
that it is harvested. The value of barley to the Korean arises from
the fact that it is the first grain to germinate in the spring. It carries
the people on until the millet and rice crops are ready. Barley and
wheat are extensively raised throughout Korea for the purpose of
making wine and beer. In other ways, however, they may be
considered almost as important as the different kinds of pulse. The
uses of barley are very numerous. Besides being used directly as
farinaceous food it becomes malt, medicine, candy, syrup, and
furnishes a number of side-dishes. Wheat comes mostly from Pyöng-
an Province, only small crops of it appearing in the other Provinces.
Barley yields spring and autumn crops, but wheat yields only the
winter crop. The poor accept wheat as a substitute for rice, and
brew a gruel from it. It is used as a paste; it figures in the native
pharmacopœia, and in the sacrifices with which the summer solstice
is celebrated.
Oats, millet, and sorghum are other important cereals in Korea.
There are six varieties of millet; the price of the finer qualities is the
same as that obtained for rice. One only of these six varieties was
found originally in the country. Sorghum is grown principally in
Kyöng-syang Province. It grows freely, however, in the south; but is
less used than wheat, millet, or oats in Korea. A curious distinction
exists between the sorghum imported from China and the native
grain. In China, sorghum is used in making sugar; when this sugar-
producing grain arrives in Korea it is found impossible to extract the
sugar. Two of the three kinds of sorghum in Korea are native, the
third coming from Central China. Oats become a staple food in the
more mountainous regions, where rice is never seen; it is dressed
like rice. From the stalk the Koreans make a famous paper, which is
used in the Palaces of the Emperor. It is cultivated in Kang-won,
Ham-kyöng, and Pyöng-an Provinces.
The Korean is omnivorous. Birds of the air, beasts of the field, and
fish from the sea, nothing comes amiss to his palate. Dog-meat is in
great request at certain seasons; pork and beef with the blood
undrained from the carcase; fowls and game—birds cooked with the
lights, giblets, head and claws intact, fish, sun-dried and highly
malodorous, all are acceptable to him. Cooking is not always
necessary; a species of small fish is preferred raw, dipped into some
piquant sauce. Other dainties are dried sea-weed, shrimps,
vermicelli, made by the women from buckwheat flour and white of
egg, pine seeds, lily bulbs, honey-water, wheat, barley, millet, rice,
maize, wild potatoes, and all vegetables of Western and Eastern
gardens; even now the list is by no means exhausted.
Their excesses make them martyrs to indigestion.
CHAPTER XI
Japan in Korea—Historical associations—In Old Fusan—Political and economic
interests—Abuse of paramountcy
JAPANESE CAVALRY
The part, which Fusan played in this war, materially assisted the
invading hosts of Japan. A settlement at Fusan, which had been
founded long since by the retainers of the Daimio of the island of
Tsu-shima, assisted by itinerant traders and deserters from the
numerous expeditions which visited its shores, had grown to such
dimensions that when the force was descried off the harbour upon
the morning of May 25th, 1592, Fusan was already in their
possession. This circumstance gave the troops immediate facilities
for disembarkation, and, in the subsequent vicissitudes of the next
six years’ campaign, expedited the progress of the war. The position
of Fusan speedily made the place a base of supplies to the army of
operation and a repairing yard for the Japanese fleet after their
disastrous engagement with the Korean ships, in an attempt to co-
operate with the victorious forces, which Konishi and Kuroda had
assembled before Pyöng-yang. After the conclusion of the first
invasion and the Japanese retreat from the north, before the
combined strength of the Chinese and Koreans on May 22nd, 1593,
Fusan became one of the fortified camps upon the coast, where the
Japanese armies passed the winter in sight of the shores of their
own land. The negotiations, which were opened in the following
year, and shifted alternately between the camp of the Commander-
in-Chief at Fusan and the Courts in China and Japan, failed.
Even at this date Japan was anxious to establish her power in
Korea by obtaining possession of the southern provinces. Foiled in
this attempt, she renewed her attack. Fusan again became the seat
of the councils of war, and the base for the second invasion. The
operations began with the siege of the Castle of Nan-on, in Chyöl-la
province, upon the morning of September 21st, 1597. Twelve
months later, the Japanese were withdrawn from Korea, and the war
came to its close. Two hundred years passed before Korea recovered
from the desolation of this conflict, which was one in which the loss
of three hundred thousand men was recorded. Moreover, the
Japanese retained Fusan, a perpetual evidence of their victory.
This early claim to the southern provinces put forward by the
Japanese plainly reveals how long standing is their wish to annex the
southern half of Korea. Even in modern times, they have embarked
upon one campaign in the interests of Korea, while they are now
ready to go to war with Russia on behalf of the same nation that
they themselves consistently bully. Their plea of Korea for the
Koreans, however, is in curious contrast to their own lawless
domination of the coveted territory. Indeed, the interests which the
Japanese have developed for themselves throughout these regions
do not disclose much consideration for the rights of the natives. The
treaty of 1876, which opened Fusan to Japanese settlers, removed
the nominal obstacles to that over-sea immigration which had been
progressing steadily during several centuries. A wave of Japanese
colonisation at once lapped the eastern, western, and southern
shores of the Hermit Kingdom.
Indications of previous incursions were given by the affinity which
existed between the language, manners, and local customs of these
newcomers and the indigenous race. The existence of this affinity
became a powerful, if impersonal, instrument in abating the
opposition of the population to the settlement. Unable to obtain the
secession of the territory which they so much desired, communities
of Japanese fringed its borders. They planted themselves wherever
there were prospects of trade, until the resources of the land were
tapped in all directions, and the control of its commerce was virtually
in their hands. As other ports were opened at the persistent
instigation of these persevering traders, however, the settlement of
the south proceeded less rapidly. In view of the changing relations
between Korea and the Powers, therefore, the Japanese passed
further afield, developing some little industry to their own advantage
wherever they went. Trade followed their flag, whether they were
within the radius of the treaty ports, or engaged in forcing the hand
of the local officials by settling beyond the limitations of their
Conventions. The success of these efforts was soon assured. Despite
the stipulations of the treaties, and in face of the objections of their
own, as well as the Korean, Government, the irrepressible activity of
these pioneers of a past generation unconsciously contributed to
that supremacy which the trade of Japan has since achieved in the
land of her former enemy.
The expansion of Japanese interests in Korea has not been
without political design. The integrity of her neighbour is bound up
with her own existence. The security of Korea emphasises the safety
of her own borders; and, as her own Empire has developed into a
first-class Power, this desire to see the kingdom respected has
become more and more the spirit of the policy upon which she has
concentrated her individual action. She has fostered the trade with
Korea because it drew together the ties which connected the two
countries. She has urged the concession of ports, and still more
ports, to foreign commerce, because the preponderance of her trade
in these open marts substantiates her claim to be the lawful
champion of the race. The progress of Korea, since the country
came under her supervision, has been more evident than any of the
difficulties which have originated out of the disposition of the
Japanese to bully and coerce the Koreans. If, upon occasion, the
results have suggested that the blind cannot lead the blind without
disaster, the rarity of mistakes reflects credit upon the judgment
which has been displayed. This combination is, of course, directed
against foreigners. Just as Japan is discarding those Western
teachers, whose genius and administrative abilities protected her in
her days of ignorance, so does she hanker after the time when she
alone may guard the interests of Korea, and supply the demands of
her markets. At present, however, it is open to question whether the
Koreans will have overcome their feelings of irritation against the
Japanese by the time that these have become thoroughly
progressive in their treatment of the Koreans. The Japanese are
more repressive in their methods than they need be.
The extraneous evidence of the power of the Japanese irritates
the Koreans, increasing the unconquerable aversion which has
inspired them against the Japanese through centuries, until, of the
various races of foreigners in Korea at the present, none are so
deservedly detested as those hailing from the Island Empire of the
Mikado. Nor is this prejudice remarkable, when it is considered that
it is the scum of the Japanese nation that has settled down upon
Korea. It is, perhaps, surprising that the animus of the Koreans
against the Japanese has not died out with time; but the fault lies
entirely with the Japanese themselves. Within recent years so much
has occurred to alter the position of Japan and to flatter the vanity
of these island people that they have lost their sense of perspective.
Puffed up with conceit, they now permit themselves to commit social
and administrative excesses of the most detestable character. Their
extravagant arrogance blinds them to the absurdities and follies of
their actions, making manifest the fact that their gloss of civilisation
is the merest veneer. Their conduct in Korea shows them to be
destitute of moral and intellectual fibre. They are debauched in
business, and the prevalence of dishonourable practices in public life
makes them indifferent to private virtue. Their interpretation of the
laws of their settlements, as of their own country, is corrupt. Might is
right; the sense of power is tempered neither by reason, justice nor
generosity. Their existence from day to day, their habits and their
manners, their commercial and social degradation, complete an
abominable travesty of the civilisation which they profess to have
studied. It is intolerable that a Government aspiring to the dignity of
a first-class Power should allow its settlements in a friendly and
foreign country to be a blot upon its own prestige, and a disgrace to
the land that harbours them.
There are some twenty-five thousand Japanese in Korea, and the
Japanese settlement is the curse of every treaty port in Korea. It is
at once the centre of business, and the scene of uproar, riot, and
confusion. In the comparative nakedness of the women, in the noise
and violence of the shopkeepers, in the litter of the streets, there is
nothing to suggest the delicate culture of Japan. The modesty,
cleanliness, and politeness, so characteristic of the Japanese, are
conspicuously absent in their settlements in this country.
Transformation has taken place with transmigration. The merchant
has become a rowdy; the coolie is impudent, violent, and, in
general, an outcast more prone to steal than to work. Master and
man alike terrorise the Koreans, who go in fear of their lives
whenever they have transactions with the Japanese. Before the
Chino-Japanese war this spirit had not displayed itself to any great
extent in the capital of the Hermit Kingdom. With the successful
conclusion of that campaign, however, the Japanese became so
aggressive in their treatment of the people that, had the choice of
two evils been possible in view of these events, the Koreans would
have preferred the Chinese and a state of dependence to the
conditions which were then introduced. The universal admiration
aroused by the conduct of the Japanese troops in the North-China
campaign of 1900-1901 has added sensibly to the vanity and egoism
of these Korean-Japanese. Convinced of their innate superiority, their
violence towards the Koreans goes on unchecked. It threatens now
to assume unparalleled dimensions. If the relations between the
Powers are to continue upon a satisfactory footing in Korea, it will be
necessary for the Japanese Government to redress those abuses
which foreigners, Japanese, and Koreans alike have combined to
denounce.
H.M.S. ASTREA
CHAPTER XII
The commercial prospects of Korea—Openings to trade—Requirements of markets
—Lack of British enterprise
The trade returns for 1900 exceeded every previous year. During
the period covered by the Boxer disturbances, however, the Korean
exports to China decreased, and the importation of foreign goods
likewise fell off. The stimulus given to the cereal trade, by the
interruption of the Manchurian export bean trade from Newchang,
and by the demand for food-supplies for the troops in China, more
than counterbalanced this temporary decline in direct native exports
and direct foreign imports. Cotton goods, however, show an increase
of £14,297 over the figures of previous years; but there is a specific
falling off in imports of British manufacture and origin, and a specific
advance in the more important lines of Japanese goods. I append a
small table revealing the comparative prosperity of British and
Japanese trade at this date: