Dive Into Python A Guide To The Python Language For Programmers Pilgrim pdf download
Dive Into Python A Guide To The Python Language For Programmers Pilgrim pdf download
https://ebookbell.com/product/dive-into-python-a-guide-to-the-
python-language-for-programmers-pilgrim-11927998
https://ebookbell.com/product/dive-into-python-3-mark-pilgrim-2525732
https://ebookbell.com/product/dive-into-python-mark-pilgrim-32704064
https://ebookbell.com/product/dive-into-python-pilgrim-mark-55668124
https://ebookbell.com/product/dive-into-python-3-2nd-edition-mark-
pilgram-7141068
Dive Into Python Mark Pilgrim
https://ebookbell.com/product/dive-into-python-mark-pilgrim-43186686
https://ebookbell.com/product/dive-into-python-3-mark-pilgrim-2463166
https://ebookbell.com/product/dive-into-python-mark-pilgrim-43033722
https://ebookbell.com/product/dive-into-python-3-mark-pilgrim-5412084
Dive Into Data Science Use Python To Tackle Your Toughest Business
Challenges 1st Edition Bradford Tuckfield
https://ebookbell.com/product/dive-into-data-science-use-python-to-
tackle-your-toughest-business-challenges-1st-edition-bradford-
tuckfield-48471960
Dive Into Python 3
■■■
Mark Pilgrim
i
Dive Into Python 3
Copyright © 2009 by Mark Pilgrim
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.
ISBN-13 (pbk): 978-1-4302-2415-0
ISBN-13 (electronic): 978-1-4302-2416-7
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Lead Editor: Duncan Parkes
Technical Reviewer: Simon Willison
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony
Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie,
Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade,
Tom Welsh
Project Managers: Richard Dal Porto and Debra Kelly
Copy Editors: Nancy Sixsmith, Heather Lang, Patrick Meader, and Sharon Terdeman
Compositor: folio 2
Indexer: Julie Grady
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-
[email protected], or visit http://www.springeronline.com.
For information on translations, please e-mail [email protected], or visit
http://www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
http://www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although
every precaution has been taken in the preparation of this work, neither the author(s) nor
Apress 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 this work.
ii
For Michael
iii
Contents at a Glance
■Foreword........................................................................................................................... xiii
■About the Author ................................................................................................................ xv
■About the Technical Reviewer........................................................................................... xvi
■Acknowledgments............................................................................................................ xvii
■Installing Python ............................................................................................................. xviii
■Chapter 1: Your First Python Program ................................................................................. 1
■Chapter 2: Native Datatypes............................................................................................... 15
■Chapter 3: Comprehensions ............................................................................................... 43
■Chapter 4: Strings .............................................................................................................. 53
■Chapter 5: Regular Expressions ......................................................................................... 69
■Chapter 6: Closures and Generators................................................................................... 87
■Chapter 7: Classes and Iterators ...................................................................................... 101
■Chapter 8: Advanced Iterators ......................................................................................... 113
■Chapter 9: Unit Testing..................................................................................................... 131
■Chapter 10: Refactoring ................................................................................................... 155
■Chapter 11: Files .............................................................................................................. 167
■Chapter 12: XML............................................................................................................... 185
■Chapter 13: Serializing Python Objects ............................................................................ 205
■Chapter 14: HTTP Web Services ....................................................................................... 225
■Chapter 15: Case Study: Porting chardet to Python 3 ...................................................... 253
■Chapter 16: Packaging Python Libraries.......................................................................... 279
■Appendix A: Porting Code to Python 3 with 2to3 ............................................................. 295
■Appendix B: Special Method Names................................................................................. 327
■Appendix C: Where to Go From Here................................................................................. 345
■Index ................................................................................................................................ 347
iv
Contents
■Foreword........................................................................................................................... xiii
■About the Author ................................................................................................................ xv
■About the Technical Reviewer........................................................................................... xvi
■Acknowledgments............................................................................................................ xvii
■Installing Python ............................................................................................................. xviii
Which Python Is Right for You? ...............................................................................................................xi
Installing on Microsoft Windows........................................................................................................... xii
Installing on Mac OS X ...........................................................................................................................xxi
Installing on Ubuntu Linux................................................................................................................xxxiii
Installing on Other Platforms ................................................................................................................ xli
Using the Python Shell ........................................................................................................................... xli
Python Editors and IDEs .......................................................................................................................xliv
■Chapter 1: Your First Python Program ................................................................................. 1
Declaring Functions ..................................................................................................................................2
Optional and Named Arguments..............................................................................................................3
Writing Readable Code..............................................................................................................................5
Documentation Strings .............................................................................................................................5
The import Search Path.............................................................................................................................6
Everything Is an Object .............................................................................................................................7
What’s an Object? ......................................................................................................................................8
Indenting Code ..........................................................................................................................................8
Exceptions ..................................................................................................................................................9
Catching Import Errors ...........................................................................................................................11
Unbound Variables..................................................................................................................................12
Running Scripts .......................................................................................................................................12
Further Reading Online...........................................................................................................................13
v
■ CONTENTS
vi
■ CONTENTS
vii
■ CONTENTS
viii
■ CONTENTS
ix
■ CONTENTS
x
■ CONTENTS
xi
■ CONTENTS
xii
Foreword
Seven years ago, I’d have looked at you incredulously and probably laughed if you had told me I would
be sitting here today writing the foreword to a book, much less the foreword to a programming book. Yet
here I am.
Seven years ago, I was just a test engineer with some scripting skills and a systems administration
background. I had little programming experience and even less passion for it.
One day, a soon-to-be-coworker of mine mentioned this “new” scripting language called Python.
He said it was easy to learn and might add to my skill set. I was wary because programmers seemed to be
so separated from my “real world” of tests and systems and users. But his description also made me
curious, so I visited the nearest bookstore and bought the first book on the subject I found.
The book I bought was the original Dive Into Python, by Mark Pilgrim. I have to believe that I am not
the only person who can say, without exaggeration, that Mark’s book changed my life and career forever.
The combination of Mark’s book, his passion for Python, his presentation of the material, and even
the Python (the language itself) fundamentally altered the way I thought. The combination drove me not
just to read “yet another book about tech stuff”; it drove me to code, to represent my ideas in a
completely new and exciting way. Mark’s passion for the language inspired me with a newfound
passion.
Now, seven years later, I’m a contributor to the Python standard library–an active community
member–and I teach the language to as many people as I can. I use it in my free time, I use it at my job,
and I contribute to it in between my daughter’s naps. Dive Into Python–and Python itself–changed me.
Python is neither the prettiest nor most flexible language out there. But it is clean, simple, and
powerful. Its elegance lies in its simplicity and its practicality. Its flexibility enables you (or anyone) to
get something–anything–done simply by “keeping out of your way.”
I've said for some time the beauty of Python is that it scales “up.” It is useful for someone who wants
only to do some math or write a simple script. And it is equally useful for programmers who want to
create large-scale systems, web frameworks, and multimillion dollar video-sharing sites.
Python has not been without its warts, though. Building a language is, at least in my mind, much
like learning to program. It’s an evolutionary process where you constantly have to question the
decisions you’ve made and be willing to correct those decisions.
Python 3 admits to some of those mistakes with its new fixes, removing some of the old warts, while
also possibly introducing some new ones. Python 3 shows a self-awareness and willingness to evolve in
much-needed ways you don't see in a lot of things.
Python 3 does not redefine, fundamentally alter, or suddenly invalidate all the Python you knew
before. Rather, it takes something that is time-proven and battle-worn and improves on it in rational,
practical ways.
xiii
■ FOREWORD
Python 3 doesn’t represent the end of the evolution of the language. New features, syntax, and
libraries continue to be added; and it will probably be added, tweaked, and removed for as long as
Python carries on.
Python 3 is simply a cleaner, more evolved platform for you, the reader, to get things done with.
Like Python 3, Dive Into Python 3 represents the evolution of something that was already very good
becoming something even better. Mark’s passion, wit, and engaging style are still there; and the material
has been expanded, improved, and updated. But like Python 3 itself, version 3 of this series
fundamentally remains the thing that originally gave me such a passion for programming.
Python’s simplicity is infectious. The passion of its community, not to mention the passion with
which the language is created and maintained, remains astounding.
I hope Mark’s passion, and Python itself, inspires you as it did me seven years ago. I hope you find
Python, and Python 3, to be as practical and powerful as the hundreds of thousands of programmers and
companies that use it across the world.
Jesse Noller
Python Developer
xiv
About the Author
■By day, Mark Pilgrim is a developer advocate for open source and open
standards. By night, he is a husband and father who lives in North Carolina with
his wife, his two sons, and his big, slobbery dog. He spends his copious free time
sunbathing, skydiving, and making up autobiographical information.
xv
■ FOREWORD
xvi
Acknowledgments
The author would like to thank his wife for her never-ending support and encouragement, without
which this book would still be an item on an ever-growing wish list.
Thank you to Raymond Hettinger for relicensing his alphametics solver so I could use it as the basis
for Chapter 8.
Thank you to Jesse Noller for patiently explaining so many things to me at PyCon 2009, so that I
could explain them to everyone else.
Finally, thank you to the many people who gave me feedback during the public writing process,
especially Giulio Piancastelli, Florian Wollenschein, and all the good people of python.reddit.com.
xvii
■ FOREWORD
Installing Python
Welcome to Python 3. Let’s dive in. In this chapter, you’ll install the version of Python 3 that’s right
for you.
mark@atlantis:~$ python3
Python 3.0.1+ (r301:69556, Apr 15 2009, 17:25:52)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Type exit() and press Enter to exit the Python interactive shell.
My web hosting provider also runs Linux and provides command-line access, but as Listing 0-2
shows, my server does not have Python 3 installed. (Boo!)
xviii
■ INSTALLING PYTHON
mark@manganese:~$ python3
bash: python3: command not found
So back to the question that started this section: “Which Python is right for you?” The answer is
simple: whichever one runs on the computer you already have.
xix
■ INSTALLING PYTHON
The first question the installer will ask you is whether you want to install Python 3 for all users or just for
you. The default choice is “Install for all users,” which is the best choice unless you have a good reason to
choose otherwise. (One reason why you might want to choose “Install just for me” is that you are
installing Python on your company’s computer and you don’t have administrative rights on your
Windows account. But then why are you installing Python without permission from your company’s
Windows administrator? Don’t get me in trouble here!)
xx
■ INSTALLING PYTHON
Next, the installer will prompt you to choose a destination directory. The default for all versions of
Python 3.1.x is C:\Python31\, which should work well for most users unless you have a specific reason to
change it. If you maintain a separate drive letter for installing applications, you can browse to it using
the embedded controls or simply type the pathname in the box below. You are not limited to installing
Python on the C: drive; you can install it on any drive, in any folder.
xxi
■ INSTALLING PYTHON
Although the next page looks complicated, it’s not really difficult. Like many installers, you have the
option not to install every single component of Python 3. If disk space is especially tight, you can exclude
certain components.
• Register Extensions allows you to double-click Python scripts (.py files) and run
them (recommended but not required). This option doesn’t require any disk
space, so there is little point in excluding it.
• Tcl/Tk is the graphics library used by the Python shell, which you will use
throughout this book. I strongly recommend keeping this option.
• Documentation installs a help file that contains much of the information on
http://docs.python.org. This option is recommended if you are on dialup or have
limited Internet access.
• Utility Scripts includes the 2to3.py script, which you’ll learn about later in this
book. It is required if you want to learn about migrating existing Python 2 code to
Python 3. If you have no existing Python 2 code, you can skip this option.
• Test suite is a collection of scripts used to test the Python interpreter. You will not
use it in this book, nor have I ever used it in the course of programming in Python.
Completely optional.
xxii
■ INSTALLING PYTHON
If you don’t know how much disk space you have, click the Disk Usage button. The installer will list
your drive letters, compute how much space is available on each drive, and calculate how much would
be left after installation.
xxiii
■ INSTALLING PYTHON
Click the OK button to return to the customization page. If you decide to exclude an option, select
the drop-down button before the option and select “Entire feature will be unavailable”. For example,
excluding the Test suite will save you a whopping 7908KB of disk space.
xxiv
■ INSTALLING PYTHON
xxv
■ INSTALLING PYTHON
The installer will copy all the necessary files to your chosen destination directory. (This happens so
quickly, I had to try it three times to even get a screenshot of it!)
xxvi
■ INSTALLING PYTHON
xxvii
■ INSTALLING PYTHON
In your Start menu, there should be a new item called Python 3.1, in which you find a program
called IDLE. Select this item to run the interactive Python shell.
Installing on Mac OS X
All modern Macintosh computers use the Intel chip (as most Windows PCs do). Older Macs used
PowerPC chips. You don’t need to understand the difference because there’s just one Mac Python
installer for all Macs.
Visit http://python.org/download/ and download the Mac installer. It will be called something like
Python 3.1 Mac Installer Disk Image, although the version number might vary. Be sure to download
version 3.x, not 2.x.
Your browser should automatically mount the disk image and open a Finder window to show you
the contents. (If this doesn’t happen, you’ll need to find the disk image in your Downloads folder and
double-click to mount it. It will be named something like python-3.1.dmg.) The disk image contains a
number of text files (Build.txt, License.txt, ReadMe.txt) and the actual installer package, Python.mpkg.
xxviii
■ INSTALLING PYTHON
Double-click the Python.mpkg installer package to launch the Mac Python installer.
The first page of the installer gives a brief description of Python itself. It then refers you to the
ReadMe.txt file (which you didn’t read, did you?) for more details.
xxix
■ INSTALLING PYTHON
The next page actually contains some important information: Python requires Mac OS X 10.3 or
later. If you are still running Mac OS X 10.2, you should upgrade. Apple no longer provides security
updates for your operating system, and your computer is probably at risk if you ever go online. Also, you
can’t run Python 3.
xxx
■ INSTALLING PYTHON
Like all good installers, the Python installer displays the software license agreement. Python is open
source and its license is approved by the Open Source Initiative. Python has had a number of owners
and sponsors throughout its history, each of which has left its mark on the software license. But the end
result is this: Python is open source, and you are allowed use it on any platform, for any purpose,
without fee or obligation of reciprocity.
xxxi
■ INSTALLING PYTHON
Because of quirks in the standard Apple installer framework, you must “agree” to the software
license to complete the installation. Because Python is open source, you are really “agreeing” that the
license is granting you additional rights instead of taking them away.
xxxii
■ INSTALLING PYTHON
The next screen allows you to change your install location. You must install Python on your boot
drive, but because of limitations of the installer, it does not enforce it. In truth, I have never had the need
to change the install location.
xxxiii
■ INSTALLING PYTHON
From this screen, you can also customize the installation to exclude certain features. If you want to
do this, click the Customize button; otherwise click the Install button.
If you choose Custom Install, the installer will present you with the following list of features:
• Python Framework is the guts of Python, and it is both selected and disabled
because it must be installed.
• GUI Applications includes IDLE, the graphical Python shell that you will use
throughout this book. I strongly recommend keeping this option selected.
• “UNIX command-line tools” includes the command-line python3 application. I
strongly recommend keeping this option, too.
• Python Documentation contains much of the information on
http://docs.python.org. This option is recommended if you are on dialup or have
limited Internet access.
• “Shell profile updater” controls whether to update your shell profile (used in
Terminal.app) to ensure that this version of Python is on the search path of your
shell. You probably don’t need to change it.
xxxiv
■ INSTALLING PYTHON
• “Fix system Python” should not be changed. It tells your Mac to use Python 3 as
the default Python for all scripts, including built-in system scripts from Apple.
This would be very bad because most of those scripts are written for Python 2, and
they would fail to run properly under Python 3.
Click the Install button to continue.
Because it installs system-wide frameworks and binaries in /usr/local/bin/, the installer will ask
you for an administrative password. There is no way to install Mac Python without administrator
privileges.
xxxv
■ INSTALLING PYTHON
After supplying the password, click the OK button to begin the installation.
xxxvi
■ INSTALLING PYTHON
The installer will display a progress meter while it installs the features you’ve selected.
Assuming that all went well, the installer will show you a big green check mark to tell you that the
installation completed successfully.
xxxvii
■ INSTALLING PYTHON
Assuming that you didn’t change the install location, you can find the newly installed files in the
Python 3.1 folder within your /Applications folder. The most important piece is IDLE, the graphical
Python shell.
xxxviii
■ INSTALLING PYTHON
xxxix
■ INSTALLING PYTHON
The Python shell is where you will spend most of your time exploring Python. Examples throughout
this book will assume that you can find your way into the Python shell.
xl
■ INSTALLING PYTHON
Python 3 is not maintained by Canonical, so the first step is to drop down this filter menu and select
“All Open Source applications”.
Once you’ve widened the filter to include all open source applications, use the Search box
immediately after the filter menu to search for Python 3.
xli
■ INSTALLING PYTHON
xlii
■ INSTALLING PYTHON
Now the list of applications narrows to just those matching Python 3. You’ll check two packages.
The first is Python (v3.0), which contains the Python interpreter.
The second package you want is immediately above: IDLE (using Python-3.0). This is a graphical
Python shell that you will use throughout this book.
xliii
■ INSTALLING PYTHON
After you’ve checked those two packages, click the Apply Changes button to continue.
The package manager will ask you to confirm that you want to add both IDLE (using Python-3.0) and
Python (v3.0).
xliv
■ INSTALLING PYTHON
The package manager will show you a progress meter while it downloads the necessary packages
from Canonical’s Internet repository.
xlv
■ INSTALLING PYTHON
Once the packages are downloaded, the package manager will automatically begin installing them.
If all went well, the package manager will confirm that both packages were successfully installed.
From here, you can double-click IDLE to launch the Python shell or click the Close button to exit the
package manager.
You can always relaunch the Python shell by going to your Applications menu, choosing the
Programming submenu, and selecting IDLE.
The Python shell is where you will spend most of your time exploring Python. Examples throughout
this book will assume that you can find your way into the Python shell.
xlvi
■ INSTALLING PYTHON
>>> 1 + 1
2
The three angle brackets, >>>, denote the Python shell prompt. Don’t type that part. That’s just to let
you know that this example is meant to be followed in the Python shell.
1 + 1 is the part you type. You can type any valid Python expression or command in the Python
shell. Don’t be shy; it won’t bite! The worst that will happen is you’ll get an error message. Commands
xlvii
■ INSTALLING PYTHON
get executed immediately (after you press Enter), expressions get evaluated immediately, and the
Python shell prints out the result.
2 is the result of evaluating this expression. As it happens, 1 + 1 is a valid Python expression. The
result, of course, is 2.
Let’s try another one (see Listing 0-4).
Pretty simple, no? But there are more things you can do in the Python shell. If you ever get
stuck!you can’t remember a command or you can’t remember the proper arguments to pass a certain
function!you can get interactive help in the Python shell. Just type help() and press Enter, as shown in
Listing 0-5.
>>> help
Type help() for interactive help, or help(object) for help about object.
There are two modes of help. You can get help about a single object, which just prints out the
documentation and returns you to the Python shell prompt. You can also enter help mode, where
instead of evaluating Python expressions, you just type keywords or command names and it will print
out whatever it knows about that command.
To enter the interactive help mode, type help() and press Enter, as shown in Listing 0-6.
>>> help()
Welcome to Python 3.1! This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
help>
Note that the prompt changes from >>> to help>. This reminds you that you’re in the interactive
help mode. Now you can enter any keyword, command, module name, function name!pretty much
anything Python understands!and read documentation on it (see Listing 0-7).
xlviii
■ INSTALLING PYTHON
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout)
You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)". Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
>>> (4)
xlix
Random documents with unrelated
content Scribd suggests to you:
prejudices which even now are so astonishing a feature of German social
life, and which were then even more powerful and far-reaching. That the
Prince and Princess should appear actually to enjoy the society of mere
painters and writers and scientists, whether they occupied any official
positions or not, seemed extraordinary and highly improper to the whole
bureaucratic element of Berlin, and must, we can well imagine, have
seriously offended the Prince’s father.
It is easy to be wise after the event. No one now can help seeing that it
would have been the truest wisdom for the young Princess to have rigidly
suppressed her natural tastes and intellectual interests, and to have led a life
of the narrowly conventional character which Prussian princesses were
expected to lead. But she was incapable of such self-suppression, which
would have seemed to her deceitful, and the mild cautions and hints at
prudence in her father’s letters were pathetically inadequate to the needs of
her critical position. She was herself still quite unaware of how closely she
was being watched and criticised. “I am very happy,” she told a guest at one
of the Court receptions, “and I am intensely proud of belonging to this
country.”
The more the Princess’s social preferences aroused the suspicion and
indignation of the Court world, the more popular she became with the
“intellectuals,” unfortunately not a profitable exchange for her as she was
then situated. We become aware of this by a passage in the Reminiscences of
Professor Schellbach, who had been mathematical tutor to Prince Frederick
William. He writes:
“The first words which the Princess addressed to me with the greatest
kindness were, ‘I love mathematics, physics, and chemistry.’ I was much
pleased, for I saw that the Prince must have given her a pleasant account of
me. Under the direction of her highly cultivated father, who had himself
studied it, Princess Victoria had become acquainted with natural science, and
had even received her first teaching from such famous men as Faraday and
Hoffman. Our beloved Princess soon revealed her love for art and science, as
well as her pleasure in setting problems of her own. Her Royal Highness at
first tried to go on with her studies in physics and mathematics under my
direction, but soon her artistic work took up the remainder of time which the
requirements of Court life left to her.”
Early in June Prince Albert carried out his plan of visiting his daughter
and son-in-law, but it was at Babelsberg, not at Coburg, as he had hoped. He
was able to report to Queen Victoria: “The relation between the young
people is all that can be desired. I have had long talks with them both, singly
and together, which gave me the greatest satisfaction.”
Prince Albert was, however, shocked to find the King of Prussia in a
terrible state:
“The King looks frightfully ill; he was very cordial and friendly, and for
the half hour he stayed with us, did not once get confused, but complained
greatly about his state of health. He is thin and fallen away over his whole
body, with a large stomach, his face grown quite small. He made many
attempts at joking in the old way, but with a voice quite broken, and features
full of pain. ‘Wenn ich einmal fort bin, wieder fort bin,’ he said, grasping his
forehead and striking it, ‘then the Queen must pay us a visit here, it will
make me so happy.’ What he meant was, ‘Wenn ich wieder wohl bin.’ ‘It is
so tedious,’ he murmured; thus it is plainly to be seen that he has not quite
given up all thought of getting better. The Prince’s whole aim is to be
serviceable to his brother. He still walks very lame, but looks well. I kept
quietly in the house all day with Vicky, who is very sensible and good.”
The Princess had special reasons for being “sensible” at this time, for, to
the great joy of the Prussian Royal family, she was enceinte.
In August Queen Victoria and the Prince Consort paid a visit of some
length to their daughter. The Queen herself describes the visit as “quite
private and unofficial,” although she carried in her train not only Lord
Malmesbury, the Foreign Secretary in Lord Derby’s Government (which had
been formed in February), but also Lord Clarendon, his predecessor, and
Lord Granville, who had been Lord President of the Council in Palmerston’s
Government.
Prince Albert, at any rate, did not neglect the opportunity of studying the
political situation. He wrote to Stockmar a letter highly approving the Prince
of Prussia’s political views, while his son-in-law he described as firm in his
constitutional principles and despising the Manteuffel Ministry, the members
of which he met with obvious coolness.
The Berliners gave a hearty reception to Queen Victoria and Prince
Albert, and the Queen declared to the Burgomaster of Berlin that she felt
exceedingly happy there, because she had realised with what love and
devotion everyone was attached to the Royal house and to her daughter.
She was delighted with old Wrangel, whom she calls a great character.
“He was full of Vicky and the marriage, and said she was an angel.” There
was a great deal of sight-seeing, mitigated by charming little gemuthlich
family dinners, and a grand review at Potsdam.
Prince Albert’s birthday occurred during the visit, and one of the Queen’s
presents to him was “a paper-weight of Balmoral granite and deer’s teeth
designed by Vicky.” “Vicky gave her portrait, a small oil one by Hartmann,
very like though not flattered, and a drawing by herself. There were two
birthday cakes. Vicky had ordered one with as many lights as Albert
numbered years, which is the Prussian custom.”
Her Majesty notes with pleasure the arrival of “our dear, excellent old
friend Stockmar,” whose presence, however, by no means gave universal
satisfaction. Indeed, Sir Theodore Martin says frankly that, although his visit
was due solely to his desire to meet the Queen and Prince Consort, it was
viewed with rancorous suspicion by the aristocratic party, who held in
abhorrence the man whom they knew to be the great advocate for the
establishment of constitutional government in Germany. He was even
accused of actively intriguing for the downfall of the Manteuffel
Administration, having, it was said, “brought in his pocket, all cut and dry
from England, the Ministry of the new era.”
Stockmar’s views of what was needful to raise Germany to her proper
place among the nations were unchanged, but age and infirmity had for some
time made him a mere looker-on. Nevertheless, it is probable that neither the
Queen nor Prince Albert in the least realised how inadvisable, in the interests
of the Princess Royal, was the old man’s visit.
It must not, however, be thought that the Prussians were indifferent to the
Princess Royal’s singular personal charm. We have a most interesting
glimpse of this in a long letter written to Queen Victoria by the beautiful and
brilliant Duchess of Manchester, herself a Hanoverian by birth, who
afterwards married the Duke of Devonshire and for many years held a
remarkable position in English society.
The Duchess relates how well the Princess Royal was looking during the
manœuvres on the Rhine, and how much she seemed to be beloved, not only
by all those who knew her, but also by those who had only seen and heard of
her.
“The English could not help feeling proud of the way the Princess Royal
was spoken of, and the high esteem she is held in. For one so young it is a
most flattering position, and certainly, as the Princess’s charm of manner and
her kind unaffected words had in that short time won her the hearts of all the
officers and strangers present, one was not astonished at the praise the
Prussians themselves bestow on her Royal Highness. The Prussian Royal
Family is so large, and their opinions politically and socially sometimes so
different, that it must have been very difficult indeed at first for the Princess
Royal, and people therefore cannot praise enough the high principles, great
discretion, sound judgment, and cleverness her Royal Highness has
invariably displayed.”
And the Duchess adds, on the authority of Field Marshal Wrangel, that
the soldiers were particularly delighted to see the Princess on horseback and
without a veil.
The Royal visit to Babelsberg came to an end all too soon, and the leave-
taking was tearful and emotional in the extreme. Queen Victoria wrote with
natural feeling, “All would be comparatively easy, were it not for the one
thought that I cannot be with her at the very critical moment when every
other mother goes to her child!”
In October of that first year of the Princess Royal’s married life, her
father-in-law became permanent Regent, owing to the continued mental
incapacity of King Frederick William IV. This filled the young Princess with
intense satisfaction, which was increased when the new Prince Regent
declared it to be his intention strictly to adhere to the letter and the spirit of
the Constitution of 1850. The great bulk of the nation rallied instantly round
him, and it seemed as if the gulf between the House of Hohenzollern and the
people of Prussia had been suddenly bridged. The Manteuffel Ministry fell
in the following month, a general election produced an enormous Liberal
majority, and the hopes of the Constitutionalists ran high. The Manteuffel
Ministry was succeeded by one of which Prince Charles Anthony of
Hohenzollern was the President. From this time forward Prince Frederick
William regularly attended the meetings of the Ministry, and Privy
Councillor Brunnemann was assigned to him as a kind of secretary and
channel of communication on State affairs.
The Princess Royal imprudently expressed to a gentleman of the Court
her satisfaction at the change in the political situation, and her words, being
repeated and exaggerated, gave great offence to the Conservative party,
which was also the party of the King. The Princess’s satisfaction was of
course shared by her father, who wrote to the sympathetic Stockmar a letter
showing no prevision of that great rock of Army administration on which
these high hopes were destined to be wrecked:
“The Regency seems now to have been secured for the Prince. We have
only news of this at present by telegrams from our children, but are greatly
delighted at this first step towards the reduction to order of a miserable
chaos. Will the Prince have the courage to surround himself with honourable
and patriotic men? That is the question, and what shape will the new
Chamber take, and what will its influence on him be?”
On November 20, 1858, Prince and Princess Frederick William moved
into the palace in Unter den Linden which was henceforth to be their
residence in Berlin; and on the following day, the Princess’s eighteenth
birthday, there was a kind of dedicatory service in the palace chapel, which
was attended by all the members of the Royal House.
HER ROYAL HIGHNESS
VICTORIA, PRINCESS ROYAL
1856
This palace had been the scene of the happy life of the Prince’s
grandfather, King Frederick William III, and of Queen Louise. The intimate
and beautiful family life that had filled these rooms was the best of omens
for the young pair, and the Princess Royal was delighted with her new home.
But the palace required to be brought up to modern standards of comfort,
and it was very difficult to have the alterations approved by the moody and
violent King. What he allowed on one day he took back with hasty blame on
the morrow. At last Prince Frederick William obtained the Royal assent to
those alterations which were absolutely urgent, together with a grant of
350,000 thalers. Among other improvements was added an eight-cornered
“Gedenkhalle” or “Memory-Hall,” in which were placed the numerous
wedding presents of the young pair, and to these, from time to time, were
added other rare and beautiful objects.
CHAPTER VI
ebookbell.com