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

Python in a nutshell Second Edition Alex Martelli instant download

Ebook installation

Uploaded by

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

Python in a nutshell Second Edition Alex Martelli instant download

Ebook installation

Uploaded by

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

Python in a nutshell Second Edition Alex

Martelli pdf download

https://ebookfinal.com/download/python-in-a-nutshell-second-
edition-alex-martelli/

Explore and download more ebooks or textbooks


at ebookfinal.com
We have selected some products that you may be interested in
Click the link to download now or visit ebookfinal.com
for more options!.

Python Cookbook 2nd ed Edition Alex Martelli

https://ebookfinal.com/download/python-cookbook-2nd-ed-edition-alex-
martelli/

Quantum Field Theory in a Nutshell Second Edition A. Zee

https://ebookfinal.com/download/quantum-field-theory-in-a-nutshell-
second-edition-a-zee/

SQL in a Nutshell 3rd Edition Kevin Kline

https://ebookfinal.com/download/sql-in-a-nutshell-3rd-edition-kevin-
kline/

C in a Nutshell 1st ed Edition Ray Lischner

https://ebookfinal.com/download/c-in-a-nutshell-1st-ed-edition-ray-
lischner/
Algorithms in a Nutshell 1st Edition George T. Heineman

https://ebookfinal.com/download/algorithms-in-a-nutshell-1st-edition-
george-t-heineman/

Java in a nutshell 2nd ed Edition David Flanagan

https://ebookfinal.com/download/java-in-a-nutshell-2nd-ed-edition-
david-flanagan/

Cisco IOS in a Nutshell 2nd ed Edition James Boney

https://ebookfinal.com/download/cisco-ios-in-a-nutshell-2nd-ed-
edition-james-boney/

LPI Linux Certification in a Nutshell Third Edition Adam


Haeder

https://ebookfinal.com/download/lpi-linux-certification-in-a-nutshell-
third-edition-adam-haeder/

Ruby in a Nutshell A Desktop Quick Reference 1st Edition


Yukihiro Matsumoto

https://ebookfinal.com/download/ruby-in-a-nutshell-a-desktop-quick-
reference-1st-edition-yukihiro-matsumoto/
Python in a nutshell Second Edition Alex Martelli Digital
Instant Download
Author(s): Alex Martelli
ISBN(s): 9780596100469, 0596100469
Edition: Second
File Details: PDF, 12.99 MB
Year: 2006
Language: english
PYTHON
IN A NUTSHELL

Second Edition

Alex Martelli

Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo


Python in a Nutshell, Second Edition
by Alex Martelli
Copyright © 2006, 2003 O’Reilly Media, Inc. 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 (safari.oreilly.com). For more information, contact
our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.

Editor: Mary T. O’Brien Cover Designer: Emma Colby


Production Editor: Matt Hutchinson Interior Designer: Brett Kerr
Copyeditor: Linley Dolby Cover Illustrator: Karen Montgomery
Proofreader: Matt Hutchinson Illustrators: Robert Romano and Jessamyn
Indexer: Johnna Dinse Read

Printing History:
March 2003: First Edition.
July 2006: Second Edition.

Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered
trademarks of O’Reilly Media, Inc. The In a Nutshell series designations, Python in a Nutshell,
the image of an African rock python, and related trade dress are trademarks of O’Reilly
Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in this book, and O’Reilly Media,
Inc. was aware of a trademark claim, the designations have been printed in caps or initial
caps.
While every precaution has been taken in the preparation of this book, the publisher and
author assume no responsibility for errors or omissions, or for damages resulting from the use
of the information contained herein.

ISBN: 978-0596-10046-9
[LSI] [2011-07-01]
Chapter 1

Table of Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Part I. Getting Started with Python


1. Introduction to Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Python Language 3
The Python Standard Library and Extension Modules 5
Python Implementations 5
Python Development and Versions 8
Python Resources 9

2. Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Installing Python from Source Code 14
Installing Python from Binaries 18
Installing Jython 20
Installing IronPython 21

3. The Python Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22


The python Program 22
Python Development Environments 26
Running Python Programs 28
The jython Interpreter 29
The IronPython Interpreter 30

iii
Part II. Core Python Language and Built-ins
4. The Python Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Lexical Structure 33
Data Types 38
Variables and Other References 46
Expressions and Operators 50
Numeric Operations 52
Sequence Operations 53
Set Operations 58
Dictionary Operations 59
The print Statement 61
Control Flow Statements 62
Functions 70

5. Object-Oriented Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Classes and Instances 82
Special Methods 104
Decorators 115
Metaclasses 116

6. Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
The try Statement 121
Exception Propagation 126
The raise Statement 128
Exception Objects 129
Custom Exception Classes 132
Error-Checking Strategies 134

7. Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Module Objects 139
Module Loading 144
Packages 149
The Distribution Utilities (distutils) 150

8. Core Built-ins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153


Built-in Types 154
Built-in Functions 158
The sys Module 168
The copy Module 172
The collections Module 173

iv | Table of Contents
The functional Module 175
The bisect Module 176
The heapq Module 177
The UserDict Module 178
The optparse Module 179
The itertools Module 183

9. Strings and Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186


Methods of String Objects 186
The string Module 191
String Formatting 193
The pprint Module 197
The repr Module 198
Unicode 198
Regular Expressions and the re Module 201

Part III. Python Library and Extension Modules


10. File and Text Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Other Chapters That Also Deal with Files 215
Organization of This Chapter 215
File Objects 216
Auxiliary Modules for File I/O 224
The StringIO and cStringIO Modules 229
Compressed Files 230
The os Module 240
Filesystem Operations 241
Text Input and Output 256
Richer-Text I/O 258
Interactive Command Sessions 265
Internationalization 269

11. Persistence and Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277


Serialization 278
DBM Modules 285
Berkeley DB Interfacing 288
The Python Database API (DBAPI) 2.0 292

Table of Contents | v
12. Time Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
The time Module 302
The datetime Module 306
The pytz Module 313
The dateutil Module 313
The sched Module 316
The calendar Module 317
The mx.DateTime Module 319

13. Controlling Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328


Dynamic Execution and the exec Statement 328
Internal Types 331
Garbage Collection 332
Termination Functions 337
Site and User Customization 338

14. Threads and Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340


Threads in Python 341
The thread Module 341
The Queue Module 342
The threading Module 344
Threaded Program Architecture 350
Process Environment 353
Running Other Programs 354
The mmap Module 360

15. Numeric Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365


The math and cmath Modules 365
The operator Module 368
Random and Pseudorandom Numbers 370
The decimal Module 372
The gmpy Module 373

16. Array Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375


The array Module 375
Extensions for Numeric Array Computation 377
The Numeric Package 378
Array Objects 378
Universal Functions (ufuncs) 399
Auxiliary Numeric Modules 403

vi | Table of Contents
17. Tkinter GUIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Tkinter Fundamentals 406
Widget Fundamentals 408
Commonly Used Simple Widgets 415
Container Widgets 420
Menus 423
The Text Widget 426
The Canvas Widget 436
Layout Management 442
Tkinter Events 446

18. Testing, Debugging, and Optimizing . . . . . . . . . . . . . . . . . . . . . . . . . 451


Testing 452
Debugging 461
The warnings Module 471
Optimization 474

Part IV. Network and Web Programming


19. Client-Side Network Protocol Modules . . . . . . . . . . . . . . . . . . . . . . . 493
URL Access 493
Email Protocols 503
The HTTP and FTP Protocols 506
Network News 511
Telnet 515
Distributed Computing 517
Other Protocols 519

20. Sockets and Server-Side Network Protocol Modules . . . . . . . . . . . . 520


The socket Module 521
The SocketServer Module 528
Event-Driven Socket Programs 533

21. CGI Scripting and Alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545


CGI in Python 546
Cookies 553
Other Server-Side Approaches 557

Table of Contents | vii


22. MIME and Network Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
Encoding Binary Data as Text 561
MIME and Email Format Handling 564

23. Structured Text: HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575


The sgmllib Module 576
The htmllib Module 580
The HTMLParser Module 583
The BeautifulSoup Extension 585
Generating HTML 586

24. Structured Text: XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591


An Overview of XML Parsing 592
Parsing XML with SAX 593
Parsing XML with DOM 598
Changing and Generating XML 606

Part V. Extending and Embedding


25. Extending and Embedding Classic Python . . . . . . . . . . . . . . . . . . . . 613
Extending Python with Python’s C API 614
Extending Python Without Python’s C API 645
Embedding Python 647
Pyrex 650

26. Extending and Embedding Jython . . . . . . . . . . . . . . . . . . . . . . . . . . . 655


Importing Java Packages in Jython 656
Embedding Jython in Java 659
Compiling Python into Java 662

27. Distributing Extensions


and Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666
Python’s distutils 666
py2exe 675
py2app 676
cx_Freeze 676
PyInstaller 676

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677

viii | Table of Contents


Chapter 2

Preface

The Python programming language manages to reconcile many apparent contra-


dictions: it’s both elegant and pragmatic, it’s both simple and powerful, it’s very
high-level yet doesn’t get in your way when you need to fiddle with bits and bytes,
it’s suitable for programming novices and great for experts, too.
This book is aimed at programmers with some previous exposure to Python, as
well as experienced programmers coming to Python for the first time from other
programming languages. The book is a quick reference to Python itself, the most
commonly used parts of its vast standard library, and some of the most popular
and useful third-party modules and packages, covering a wide range of applica-
tion areas, including web and network programming, GUIs, XML handling,
database interactions, and high-speed numeric computing. The book focuses on
Python’s cross-platform capabilities and covers the basics of extending Python
and embedding it in other applications, using either C or Java™.

How This Book Is Organized


This book has five parts, as follows.

Part I, Getting Started with Python


Chapter 1, Introduction to Python
Covers the general characteristics of the Python language and its implementa-
tions, and discusses where to get help and information.
Chapter 2, Installation
Explains how to obtain and install Python on your computer(s).
Chapter 3, The Python Interpreter
Covers the Python interpreter program, its command-line options, and how it
is used to run Python programs and in interactive sessions. The chapter also

ix
mentions text editors that are particularly suitable for editing Python
programs and auxiliary programs for thoroughly checking your Python
sources, and examines some full-fledged integrated development environ-
ments, including IDLE, which comes free with standard Python.

Part II, Core Python Language and Built-ins


Chapter 4, The Python Language
Covers Python syntax, built-in data types, expressions, statements, and how
to write and call functions.
Chapter 5, Object-Oriented Python
Explains object-oriented programming in Python.
Chapter 6, Exceptions
Covers how to deal with errors and abnormal conditions in Python programs.
Chapter 7, Modules
Covers how Python lets you group code into modules and packages, how to
define and import modules, and how to install third-party Python extensions
that are packaged in standard Python ways.
Chapter 8, Core Built-ins
Refers to built-in data types and functions, and some of the most funda-
mental modules in the standard Python library (roughly, modules supplying
functionality that, in some other languages, is built into the language itself).
Chapter 9, Strings and Regular Expressions
Covers Python’s powerful string-processing facilities, including Unicode
strings and regular expressions.

Part III, Python Library and Extension Modules


Chapter 10, File and Text Operations
Explains how to deal with files and text processing using built-in Python file
objects, many modules from Python’s standard library, and platform-specific
extensions for rich text I/O. The chapter also covers issues of international-
ization and localization, and the specific task of defining interactive text-
mode command sessions with Python.
Chapter 11, Persistence and Databases
Introduces Python’s serialization and persistence mechanisms, as well as
Python’s interfaces to DBM databases, the Berkeley Database, and relational
(SQL-based) databases.
Chapter 12, Time Operations
Covers how to deal with times and dates in Python, using the standard library
and popular extensions.
Chapter 13, Controlling Execution
Explains how to achieve advanced execution control in Python, including
execution of dynamically generated code and control of garbage-collection
operations. The chapter also covers some Python internal types, and the

x | Preface
specific issue of registering “clean-up” functions to be executed at program-
termination time.
Chapter 14, Threads and Processes
Covers Python’s functionality for concurrent execution, both via multiple
threads running within one process and via multiple processes running on a
single machine. The chapter also covers how to access the process’s environ-
ment, and how to access files via memory-mapping mechanisms.
Chapter 15, Numeric Processing
Shows Python’s features for numeric computations, both in standard library
modules and in third-party extension packages; in particular, the chapter
covers how to use decimal floating-point numbers instead of the default
binary floating-point numbers. The chapter also covers how to get and use
pseudorandom and truly random numbers.
Chapter 16, Array Processing
Covers built-in and extension packages for array handling, focusing on the
traditional Numeric third-party extension, and mentions other, more recently
developed alternatives.
Chapter 17, Tkinter GUIs
Explains how to develop graphical user interfaces in Python with the Tkinter
package included with the standard Python distribution, and briefly mentions
other alternative Python GUI frameworks.
Chapter 18, Testing, Debugging, and Optimizing
Deals with Python tools and approaches that help ensure your programs are
correct (i.e., that your programs do what they’re meant to do), find and
correct errors in your programs, and check and enhance your programs’
performance. The chapter also covers the concept of “warning” and the
Python library module that deals with it.

Part IV, Network and Web Programming


Chapter 19, Client-Side Network Protocol Modules
Covers many modules in Python’s standard library that help you write
network client programs, particularly by dealing with various network proto-
cols from the client side and handling URLs.
Chapter 20, Sockets and Server-Side Network Protocol Modules
Explains Python’s interfaces to low-level network mechanisms (sockets),
standard Python library modules that help you write network server
programs, and asynchronous (event-driven) network programming with stan-
dard modules and the powerful Twisted extension.
Chapter 21, CGI Scripting and Alternatives
Covers the basics of CGI programming, how to perform CGI programming in
Python with standard Python library modules, and how to use “cookies” to
deal with session-state in HTTP server-side programming. The chapter also
mentions many alternatives to CGI programming for server-side web
programming through popular Python extensions.

Preface | xi
Chapter 22, MIME and Network Encodings
Shows how to process email and other network-structured and encoded
documents in Python.
Chapter 23, Structured Text: HTML
Covers Python library modules that let you process and generate HTML
documents.
Chapter 24, Structured Text: XML
Covers Python library modules and popular extensions that let you process,
modify, and generate XML documents.

Part V, Extending and Embedding


Chapter 25, Extending and Embedding Classic Python
Shows how to code Python extension modules using C and other classic
compiled languages, how to embed Python in applications coded in such
languages, and alternative ways to extend Python and access existing C, C++,
and Fortran libraries.
Chapter 26, Extending and Embedding Jython
Shows how to use Java classes from the Jython implementation of Python,
and how to embed Jython in applications coded in Java.
Chapter 27, Distributing Extensions and Programs
Covers the tools that let you package Python extensions, modules, and appli-
cations for distribution.

Conventions Used in This Book


The following conventions are used throughout this book.

Reference Conventions
In the function/method reference entries, when feasible, each optional parameter
is shown with a default value using the Python syntax name=value. Built-in func-
tions need not accept named parameters, so parameter names are not significant.
Some optional parameters are best explained in terms of their presence or
absence, rather than through default values. In such cases, I indicate that a param-
eter is optional by enclosing it in brackets ([]). When more than one argument is
optional, the brackets are nested.

Typographic Conventions
Italic
Used for filenames, program names, URLs, and to introduce new terms. Also
used for Unix commands and their options.
Constant width
Used for all code examples, as well as for all items that appear in code,
including keywords, methods, functions, classes, and modules.

xii | Preface
Constant width italic
Used to show text that can be replaced with user-supplied values in code
examples.
Constant width bold
Used for commands that must be typed on the command line, and occasion-
ally for emphasis in code examples or to indicate code output.

Using Code Examples


This book is here to help you get your job done. In general, you may use the code
in this book in your programs and documentation. You do not need to contact the
publisher for permission unless you’re reproducing a significant portion of the
code. For example, writing a program that uses several chunks of code from this
book does not require permission. Selling or distributing a CD-ROM of examples
from O’Reilly books does require permission. Answering a question by citing this
book and quoting example code does not require permission. Incorporating a
significant amount of example code from this book into your product’s documen-
tation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the
title, author, publisher, and ISBN. For example: “Python in a Nutshell, Second
Edition, by Alex Martelli. Copyright 2006 O’Reilly Media, Inc., 0-596-10046-9.”

How to Contact Us
I have tested and verified the information in this book to the best of my ability,
but you may find that features have changed (or even that I have made mistakes!).
Please let the publisher know about any errors you find, as well as your sugges-
tions for future editions, by writing to:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-928-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
There is a web page for this book, which lists errata, examples, and any addi-
tional information. You can access this page at:
http://www.oreilly.com/catalog/pythonian2
To ask technical questions or comment on the book, send email to:
bookquestions@oreilly.com
For more information about books, conferences, resource centers, and the
O’Reilly Network, see the O’Reilly web site at:
http://www.oreilly.com

Preface | xiii
Safari® Enabled
When you see a Safari® Enabled icon on the cover of your favorite
technology book, that means the book is available online through
the O’Reilly Network Safari Bookshelf.
Safari offers a solution that’s better than e-books: it’s a virtual
library that lets you easily search thousands of top tech books, cut and paste code
samples, download chapters, and find quick answers when you need the most
accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments
My heartfelt thanks to everybody who helped me out on this book, both in the
first edition and in its current second edition. Many Python beginners, practitio-
ners, and experts have read drafts of parts of the book and have offered feedback
to help me make the book clear, precise, accurate, and readable. Out of all of
them, for the quality and quantity of their feedback and other help, I must single
out for special thanks my colleagues at Google, especially Neal Norwitz and
Mohsin Ahmed.
The first edition received indispensable help from Python experts in specific areas
(Aahz on threading, Itamar Shtull-Trauring on Twisted, Mike Orr on Cheetah,
Eric Jones and Paul Dubois on Numeric, and Tim Peters on threading, testing,
and optimization), a wonderful group of technical reviewers (Fred Drake, Magnus
Lie Hetland, Steve Holden, and Sue Giller), and the book’s editor, Paula
Ferguson. The second edition benefited from the efforts of editors Jonathan
Gennick and Mary O’Brien, and technical reviewers Ryan Alexander, Jeffery
Collins, and Mary Gardiner. I owe special thanks to the wonderful folks in the
O’Reilly Tools Group, who (both directly and personally, and through the helpful
tools they developed) helped me through several difficult technical problems.
As always, even though they’re back in my native Italy and my career with Google
has taken me to California, my thoughts go to my family: my children Flavia and
Lucio, my sister Elisabetta, and my father Lanfranco.
But the one, incredible individual to which my heart gushes out in gratitude, and
more than gratitude, is my wife, Anna Martelli Ravenscroft, my co-author in the
second edition of the Python Cookbook, a fellow Python Software Foundation
member, and the harshest, most wonderful technical reviewer any author could
possibly dream of. Besides her innumerable direct contributions to this book,
Anna managed to create for me, out of thin air, enough peace, quiet, and free time
over the last year (despite my wonderful and challenging responsibilities as Uber
Tech Lead for Google) to make this book possible. Truly, this is her book at least
as much as it is mine.

xiv | Preface
Getting Started with Python
I

This is the Title of the Book, eMatter Edition


Copyright © 2011 O’Reilly & Associates, Inc. All rights reserved.
Chapter 1Introduction

Introduction to Python
1

Python is a general-purpose programming language. It has been around for quite a


while: Guido van Rossum, Python’s creator, started developing Python back in
1990. This stable and mature language is very high-level, dynamic, object-
oriented, and cross-platform—all characteristics that are very attractive to devel-
opers. Python runs on all major hardware platforms and operating systems, so it
doesn’t constrain your platform choices.
Python offers high productivity for all phases of the software life cycle: analysis,
design, prototyping, coding, testing, debugging, tuning, documentation, deploy-
ment, and, of course, maintenance. Python’s popularity has seen steady,
unflagging growth over the years. Today, familiarity with Python is an advantage
for every programmer, as Python has infiltrated every niche and has useful roles to
play as a part of any software solution.
Python provides a unique mix of elegance, simplicity, practicality, and power.
You’ll quickly become productive with Python, thanks to its consistency and
regularity, its rich standard library, and the many third-party modules that are
readily available for it. Python is easy to learn, so it is quite suitable if you are new
to programming, yet at the same time, it is powerful enough for the most sophisti-
cated expert.

The Python Language


The Python language, while not minimalist, is rather spare for good pragmatic
reasons. Once a language offers one good way to express a design idea, adding
other ways has only modest benefits, while the cost in terms of language
complexity grows more than linearly with the number of features. A complicated
language is harder to learn and master (and implement efficiently and without
bugs) than a simpler one. Any complications and quirks in a language hamper
productivity in software maintenance, particularly in large projects, where many
developers cooperate and often maintain code originally written by others.

3
Python is simple, but not simplistic. It adheres to the idea that if a language
behaves a certain way in some contexts, it should ideally work similarly in all
contexts. Python also follows the principle that a language should not have
“convenient” shortcuts, special cases, ad hoc exceptions, overly subtle distinc-
tions, or mysterious and tricky under-the-covers optimizations. A good language,
like any other designed artifact, must balance such general principles with taste,
common sense, and a high degree of practicality.
Python is a general-purpose programming language, so Python’s traits are useful
in just about any area of software development. There is no area where Python
cannot be part of an optimal solution. “Part” is an important word here; while
many developers find that Python fills all of their needs, Python does not have to
stand alone. Python programs can easily cooperate with a variety of other soft-
ware components, making it an ideal language for gluing together components
written in other languages.
Python is a very-high-level language (VHLL). This means that Python uses a
higher level of abstraction, conceptually farther from the underlying machine,
than do classic compiled languages such as C, C++, and Fortran, which are tradi-
tionally called high-level languages. Python is also simpler, faster to process, and
more regular than classic high-level languages. This affords high programmer
productivity and makes Python an attractive development tool. Good compilers
for classic compiled languages can often generate binary machine code that runs
much faster than Python code. However, in most cases, the performance of
Python-coded applications proves sufficient. When it doesn’t, you can apply the
optimization techniques covered in “Optimization” on page 474 to enhance your
program’s performance while keeping the benefits of high programming
productivity.
Newer languages such as Java and C# are slightly higher-level (farther from the
machine) than classic ones such as C and Fortran, and share some characteristics
of classic languages (such as the need to use declarations) as well as some of
VHLLs like Python (such as the use of portable bytecode as the compilation target
in typical implementations, and garbage collection to relieve programmers from
the need to manage memory). If you find you are more productive with Java or
C# than with C or Fortran, try Python (possibly in the Jython or IronPython
implementations, covered in “Python Implementations” on page 5) and become
even more productive.
In terms of language level, Python is comparable to other powerful VHLLs like
Perl or Ruby. The advantages of simplicity and regularity, however, remain on
Python’s side.
Python is an object-oriented programming language, but it lets you develop code
using both object-oriented and traditional procedural styles, and a touch of the
functional programming style, too, mixing and matching as your application
requires. Python’s object-oriented features are like those of C++, although they
are much simpler to use.

4 | Chapter 1: Introduction to Python


Discovering Diverse Content Through
Random Scribd Documents
oppose. Instigated by intrigues, and offers of all kinds, made by
French emissaries sent for that purpose, Bonaparte found his Milan
decrees, declaring the whole coasts of Great Britain and her
extensive colonies in the four quarters of the world in a state of
blockade, to be of no use without a navy to support it, and not
having one that dared show its face upon the ocean, had no means
to carry his decrees into execution. His eagle eye at once saw that
by making a tool of the United States, and embroiling them with
England, he might make a great diversion in his favour. He,
therefore, induced their cabinets to enter into his plans, backed, it
was said, “by good, weighty, golden reasons, and insisted upon a
new maritime law,” which would strike a death blow at our dominion
of the sea, and at once evade all blockade. The law I allude to was,
that the neutral flag or vessel should permit the ship wearing it to
carry the cargo of an enemy free of capture from the other
belligerent, who met it on the sea or elsewhere.
It was very extraordinary that America found little fault with France,
who first commenced the general blockade by the issue of her Milan
decrees, and who confiscated all the United States’ vessels that were
captured by her men-of-war or privateers with British colonial or
other produce on board, coming directly or indirectly from any port
of the United Kingdom of Great Britain and her colonies. Had they
merely touched or been driven by stress of weather into an English
port, or even boarded by a British cruiser, it was sufficient to
condemn them as lawful prizes in a French Court of Admiralty, when
met at sea by French armed vessels, and detained. England waited
with great patience, thinking that all the neutral powers, but above
all America, would protest against the measure, and join her who
was fighting for the liberties of all the world against the iron grasp of
Bonaparte, and his intended universal dominion. The United States,
on the contrary, put up with the seizure of their vessels by France,
and when Great Britain was obliged, after the greatest forbearance,
to declare the whole coast of France and her allies in a state of
blockade—which she had the means of doing, having more than one
thousand men-of-war of different sizes at sea or in commission,
ready effectually to carry this measure into operation—they grew
outrageous because she would not permit them to be our secret
enemy, and carry the trade of France in their ships, under the new
maritime law they proposed, viz., that a neutral ship and flag were
to make an enemy’s cargo neutral also. The above was one of the
causes that led to the war.
Impressment of seamen or sailors out of their vessels is another
source of complaint against this country. To this latter act England
was driven by the conduct of citizens of the United States, decoying
men to desert whenever any of our ships, whether men-of-war or
merchant vessels, put into their harbours. The enticing our seamen
away to man their vessels naturally made us search for British
subjects whenever British men-of-war boarded any of our ships,
whether at sea or in foreign parts, particularly when we knew the
easy method by which English subjects were naturalised and gained
American protections.
I recollect a very fine young seaman whom we took out of an
American ship at Messina in Sicily, when I was a lieutenant of the
Melpomene frigate. On being brought on board he produced his
United States’ protection, and requested to be sent back to his ship.
He wrote to the American consul to claim him, and the master of his
ship came on board to demand him as an American citizen. Having
strong suspicion that he was an English subject,—notwithstanding
the clamour raised by the Yankee master and consul, and the
production of his protection; yet, from his not having any nasal
twang when he spoke, and not using the general slang words of that
country, such as “I guess,” “I calculate,” etc.,—we kept him on board
that night. The next morning he came on the quarter-deck of the
frigate, and gave up his American protection and said, “I will not
deny my country—I am a native of Swansea, in Wales, and I got that
protection when I sailed last voyage in a merchant ship from
Liverpool to New York, in the following manner. On my arrival at New
York I was told that by paying two dollars I could get a protection of
citizenship, which would prevent my being pressed on board an
English man-of-war. The way it was managed was this:—I was put
into a large cradle made on purpose to hold men; I was then rocked
by them for a minute or two, and afterwards taken before the proper
authorities by the old couple, who made oath they had known me
ever since I was in my cradle—no further questions were asked, the
matter being quite understood between the parties,—I paid the fees,
the protection was granted, and, having given the old folks two
dollars for their trouble, I became a ‘registered American citizen,’ and
that, sir,” he said, “is the way British seamen are kidnapped in the
States—in short, it is a regular trade, and hundreds of seamen that
have protections got them in the same manner.”
A knowledge of the various tricks played on the other side of the
Atlantic to entice away our seamen, made the officers of the British
navy more anxious to recover their sailors, which of course at times
caused some irritating disputes with the masters and skippers of the
American vessels. These magnified every trifle, and reported all the
circumstances to people who were paid by that part of the press in
the French interest to make the worst of everything, in order to
inflame the public mind against this country, particularly after the
affair of the Leopard (50), taking our deserters out of the American
frigate Chesapeake (48), and the unfortunate event of H.M.S.
Leander, when a man was killed by accident by her firing to bring-to
a vessel under the United States’ flag off New York for the purpose
of examining her.
The Americans acted with great wisdom and foresight previous to
their declaration of war, by putting on the embargo and passing the
“Non-intercourse Bill” with England two years before. By that wise
act they were enabled to get home their trade from all parts of the
world, and having done this, they insulted our flag by sending a 58-
gun ship, commanded by Commodore Rogers, to fire into the Little
Belt corvette of 18-guns, commanded by Captain Bingham, cruising
near their coast, and killing several of her men and wounding others.
This affair had two meanings. First to revenge the death of their
citizens slain in the Chesapeake frigate, and on board the merchant
ship off New York; and secondly to induce us to declare war against
them, to make it more popular with the generality of the people of
the States, that the Government might be able to throw the blame
upon England. Britain having her hands full in other places, fighting
for the liberties of the world, making at the same time a desperate
struggle for her own existence, and most nobly striving to liberate
other powers from the grasp of Bonaparte, was not willing at this
most critical period to have another foe; she therefore tried
something in protocol fashion of the present day, but it failed as all
half-measures generally do.
America laughed at it, and commenced biting our heels, while John
Bull was tossing the dogs in front. They had the wisdom to perceive
the great error England had committed in not seeing that war was
inevitable, and that she ought to have declared it two or three years
before, and not have allowed her to get the whole of her vessels
safe into port. Our politeness and good breeding enabled them to
secure all or most of their shipping, in order to enable them to man
their ships of war and privateers with picked sailors. Their seamen
being thrown out of employ, were glad to enter on board their men-
of-war and privateers for the almost certain chance of a rich harvest,
by capturing our East and West Indiamen.
This was the great mistake England committed; for had we gone to
war at an earlier period when the seas were covered with American
merchant ships, they would have been swept into our harbours, and
she would have been completely at our mercy, and twelve months at
that time would have settled our disputes far more amicably than
the unsatisfactory method adopted in the year 1815.
Natural affection, intimate connections with this country, a common
language, and a wish to incline to a reasonable adjustment of
claims, would probably have settled our quarrel, and not have left
the boundary line as a further bone of contention. But we were
unfortunately so delighted with the success of our allies and our own
gallant army, by the capture of Paris, and other deeds in Europe,
added to the abdication of Napoleon, that American matters were
left nearly in the same state as before the war, although we had the
means at that period to have settled everything in a most
satisfactory manner. The country was like,—or might be compared
to,—soldiers and sailors who had received so much pay and prize-
money that they got drunk. Great Britain was intoxicated with the
honour and renown which their countrymen in the army and navy
had gained for them, and never thought of the morrow. Indeed, up
to the present time, 1839, they have been living upon the principal
of credit, for we have put, I fear, very little by or out to interest
which was then gained, and which has been most woefully frittered
away ever since, until the country has at last almost run bankrupt:
for we are spit upon in Spain, treated with contempt in Portugal,
despised in France, laughed at in Russia, kicked in Canada, and in a
fine olla podrida in India and China.

FINIS.

Note.—Vice-Admiral William Stanhope Lovell, R.N., K.H., was


born September 15th, 1788. Married, 2nd January, 1822, Selina,
youngest daughter of Sir Henry Crewe, Bart., of Calke Abbey,
Derby, and by her, who died on the 30th March, 1838, had issue
one son and three daughters, who survive him. Vice-Admiral
Lovell died in 1859, “sans peur et sans reproche.” Was buried at
Bexley, Kent.
APPENDIX.
Having, in the foregoing narrative, stated, in justification of our
mode of warfare in America, some of the causes which led to our
adoption of the system of retaliation, I beg to subjoin two extracts
from the Annual Register of the year 1814, as well as copies of
public documents, which a friend has most kindly favoured me with,
which fully bear me out in saying that we were in a manner
compelled to adopt the system we pursued, i.e., to teach the
Americans that we had the power to return with interest the
inhuman mode of warfare with which they began the campaign.

“From several causes it was not to be expected that the war


between Britain and America would be carried on in the most
humane and honourable mode, especially by the Americans;
they had not yet forgotten the war of the revolution, and by our
employment of the Indians, though they set us the example,
the consequences were such as might be dreaded. In their
different invasions of Canada, the greatest inhumanities were
exercised; especially at Sandwich, at the settlements on the
Thames, at York, and at Fort George. Finding that
remonstrances against this mode of conducting the war
produced no effect, General Sir George Prevost at length issued
a proclamation announcing a severe retaliation on the
Americans, while at the same time he earnestly deprecated this
mode of warfare.”—Annual Register, p. 318, Principal
Occurrences, 1814.

“A proclamation issued by General Sir George Prevost, Bart.,


announces, after long forbearance, a severe retaliation on the
Americans for their inhuman mode of warfare in their different
invasions of Canada, especially for their having, in the midst of
a severe Canadian winter, wantonly burnt the beautiful village of
Newark, and turned out four hundred helpless women and
children to perish in the snow, and through the severity of the
season, without shelter, and without a remnant of property. This
case is made out with the utmost distinctness against the
Americans, not only in this, but in a number of other instances,
at Sandwich, at the settlements on the Thames, at York, and at
Fort George. General Sir George Prevost earnestly deprecates
this mode of warfare; but he justly observes that ‘since it has
been so long persevered in by the enemy, retaliation becomes
an imperious duty.’ But he at the same time says, ‘that he will
no longer pursue a system of warfare so revolting to his own
feelings, and so uncongenial to the British character, unless
forced to it by the future measures of the enemy.’”—Annual
Register, p. 27; Principal Occurrences, 1814.

I trust that I have fully vindicated our mode of warfare in America,


by showing that we were driven to it by the great inhumanities so
frequently committed by the enemy, and when forbearance and
remonstrance failed, nothing was left but to teach them that when
goaded beyond endurance—four hundred helpless women and
children turned out to perish in the frost and snow of a severe
Canadian winter from the village of Newark, besides wanton
barbarities committed in various other places—the British lion was at
length aroused from his slumber, and that the fires which the
Americans had lit in other places, reached the public works of their
capital—Washington.

Copies of Correspondence.
“Head-quarters, British Troops,
“Bank of the St. Lawrence,
“14th Nov., 1813.
“Sir,—
“The object of the present communication, which is made by
desire of the officers in command of the British forces in this
neighbourhood, is, in the first instance, to claim as prisoners
two American officers who were taken on the morning of the
11th, previous to the action, and deserted to their own shore
while on the way to Prescott.
“I enclose a copy of their paroles.
“William Gilkinson, Esq., of Prescott, is the bearer of this flag,
and I am instructed to request that you will facilitate his
passage to the Commanding General of the United States’ Army,
to whom he is desirous of making a representation on the
subject of the plunder and destruction of his property by the
American troops in this neighbourhood. And on this subject I
am instructed to protest in the most solemn manner against
that system of rapine and plunder of the property of the
peaceful and unoffending inhabitants which has marked the
progress of the American army during its short continuance in
this province; and I am further to entreat that his Excellency the
Commander-in-Chief of the United States’ Army will allow no
consideration arising out of the circumstances of the disparity of
rank of the British officer by whom he is so called upon, to
restrain his Excellency from immediately disavowing this system
so disgraceful to a civilized army, and affording every fair
indemnity to the individual sufferers; or that he will, by an open
avowal that the system complained of is an authorized one,
leave it in the option of the general officer (hourly expected to
assume the command of the powerful and rapidly increasing
British force in this neighbourhood), to employ it in such acts of
just retaliation upon the persons and property of the inhabitants
of the right bank of the St. Lawrence as he may think fit, as
commensurate with the treatment of the inhabitants on this
side.
“I have the honour to be, Sir, very respectfully,
“Your most obedient humble servant,
“(Signed) T. HARVEY, Lieut.-Col.,
“D.C.G. to the British Forces
“in the Canadas.”

“Head Quarters, Montreal,


“2nd June, 1814.
“Sir,—
“I have the honour to transmit to you a copy of a letter which I
have written to Lieut.-General Drummond, in consequence of
the late disgraceful conduct of the American troops in the
wanton destruction of private property on the north shores of
Lake Erie, in order that if the war with the United States
continues, you may, should you judge it advisable, assist in
inflicting that measure of retaliation which shall deter the enemy
from a repetition of similar outrages.
“I have, &c.,
“(Signed) GEORGE PREVOST,
“Commander of the Forces.
“To Vice-Admiral the Honourable
“Sir A. Cochrane, K.B., &c., &c.”

“Head Quarters, Montreal,


“1st June, 1814.
“Sir,—
“It is with sincere regret and disappointment that I perused the
detail of illiberal and wanton devastation and unjustifiable
outrage reported in your letter of the 27th ult., and Major-
General Riall’s of the 19th, to have been committed in the
vicinity of the village of Dover, and on its unoffending
inhabitants, by the conflagration of their dwelling-houses and
their mills.
“I cherished the hope that the severe, although just, retaliation
inflicted for the destruction of the village of Newark would have
deterred the enemy from similar acts of barbarity; under that
impression, I issued a proclamation of the 4th January last,
which has since been most scrupulously adhered to by the
troops under my command, and it is with painful reluctance I
now feel myself compelled to return to a system so abhorrent to
those principles of humanity which have always animated and
characterized Britons.
“But such horrors cannot be suffered to remain without notice
or unrevenged; you must, therefore, transmit by a flag of truce
to the officer commanding the American force nearest to you a
statement of those atrocities, with information that you have my
instructions to inflict a severe retribution for them; you may
assure him that the same will be repeated for every act of such
outrage committed on the defenceless and peaceable settlers of
our frontier, and that the British fleet on the coast of America
will be called upon to assist in the measure of just retaliation.
“I have, &c.,
“(Signed) GEORGE PREVOST,
“Commander of the Forces.
“To Lieut.-Gen. Drummond, &c., &c.,
“Com. Upper Canada.”

“Tonnant, Halifax,
“5th Oct., 1814.
“Sir,—
“I have the honour to acknowledge the receipt of your
Excellency’s letter of the 3rd August, acquainting me of the
repetition on the part of the enemy of the disgraceful outrages
committed by him on the north shores of Lake Erie.
“I have therefore reiterated my order of retaliation of the 18th
July, of which a copy was sent to your Excellency, and given
further directions for the distressing him south of the Delaware,
to the utmost of our power; from that river northward I have
restrained the squadron from acting in full execution of its
purport until I see what change the late events may produce in
that quarter.
“I have the honour to be,
“Your Excellency’s most obedient humble servant,
“ALEXANDER COCHRANE,
“Vice-Admiral and Commander-in-Chief.
“To his Excellency
“Lieut.-General Sir Geo. Prevost, Bt.,
“Commander of the Forces, &c., &c.”

“Head Quarters, Montreal,


“August 6, 1814.
“My Lord,—
“I have the honour to transmit to your Lordship a copy of a
letter I have addressed to Vice-Admiral the Hon. Sir A.
Cochrane, respecting the late wanton and disgraceful conduct of
the enemy in the burning of the villages of Queen Town and St.
David’s, on the Erie frontier.
“J. W.
“To Earl Bathurst.”
“Head Quarters, Montreal,
“30th Sept., 1814.
“Sir,—
“I have the honour to acknowledge your three letters of the
19th inst., which have been laid before the Commander of the
Forces, with regard to the miseries which the enemy have again
made on Port Talbot; his Excellency is of opinion that it is the
act of Westbrook, who is gratifying private animosities with a
heartless band; he scarcely conceives it to have been authorized
by the Government of the U.S., and requests to be informed
who commanded the enemy’s force employed on this occasion.
The Commander of the Forces hopes that precautionary
measures have been taken to frustrate the design of the enemy
upon Long Point, should the execution of it be attempted. If you
consider it necessary to retaliate for the unjustifiable act of
carrying off Colonel Burnell, you have his Excellency’s authority
to do so, or else, if you prefer it, two respectable American
citizens may be taken as hostages for him from Hamilton.

“To Lieut.-General Drummond.”

Witherby & Co., Printers, 325a, High Holborn, W.C.

FOOTNOTES:
[A] Colonel Thomas Stanhope Badcock, of Little Missenden
Abbey, Bucks, and of Maplethorpe Hall, Lincolnshire, married
Anne, daughter of William Buckle, Esq., of the Mythe House and
Chasely, in Gloucestershire, by Anne, daughter of George
Turberville, Esq. The family is descended from Sir Salathiel Lovell,
of Harleston, co. Northampton, one of the Barons of the
Exchequer, whose youngest daughter Jane married Richard
Badcock, Esq. Of the two elder daughters, Maria married Joseph
Townshend, Esq., and died without issue; Penelope married the
Rev. Michael Stanhope, D.D., canon of Windsor, and died 1738,
leaving with other issue Arthur Charles Stanhope, Esq., father of
Philip Stanhope, who, succeeding to the honours of his family in
1773, became fifth Earl of Chesterfield. Sir Salathiel Lovell had
two sons, Samuel, his heir, a Welsh judge, who married in 1692
Miss Sergeant, and left one son, Samuel, and one daughter,
Rachel Jane, married in 1732 Richard Edgeworth, Esq., of
Edgeworthstown, co. Longford, who died in 1764, leaving issue.
[B] The eldest, Anne Bethia, married 21st September, 1809,
Lieut.-General Sir Jasper Nicholls, K.C.B. (Commander-in-Chief at
Madras and afterwards Commander-in-Chief in India), and had
eight daughters and one son. Lady Nicholls died at Rome in 1844.
Sophia Lovell married 9th June, 1814, the Rev. James Duke
Coleridge, D.C.L., eldest son of Colonel Coleridge, of Heath’s
Court, Ottery St. Mary’s, Devon, and had two daughters. Mrs.
Coleridge died at Torquay in 1874.
[C] Torpedo vulgaris.
[D] It was near a vintage.
[E] Afterwards Sir John Chambers White.
[F] Taken and destroyed.
[G] The French ship of the line, L’Achille, on fire and blowing up.
[H] Being a man of plain common-sense, I never could to this day
understand the policy of our training up foreign officers of all
nations in our service to sting ourselves. Surely our rulers forget
the sensible fable of Æsop, “The countryman and the viper.” We
took the Russians from frost and snow, thawed them in our
bosoms, and the time may yet come when they may sting us.
“Tempus omnia monstrat.”
[I] Sir Lovell Benjamin Lovell, K.C.B., K.H., commenced in the
Royal Bucks Militia in 1804, and entered as cornet (by purchase)
the 14th Light Dragoons, November, 1805; served at the taking of
Monte Video, under Sir Samuel Auchmuty, in 1807, and
subsequently in the Peninsula, including the battles of Talavera,
the Coa, Busaco, Fuentes d’Onor (wounded), Salamanca, Vittoria,
the Pyrenees, Nive, Ortherg, and Toulouse; actions or skirmishes
near Talavera, Sexmiro, Val de la Mula, La Meares, Freixeda,
Guarda, Coimbra, Valle, Venda de Sierra, Pombal, Redinha,
Miranda de Corvo, Coa, Galligos, Nave d’Aver, Espiga, near
Fuentes d’Onor, Llerena, near Salamanca, St. Christova, Bueda,
Castrillos, Foncastin, Matylla; at Burgos, Osma, Huarte,
Pampeluna, Vale de Bastan, Pass of Maya, Lines of Ainho, Cambo,
Hasparren, Helite, Garris, Sauveterre, St. Gladie, Buelho, Garlier,
San Roman—total, 10 general actions, 40 minor actions or
skirmishes, besides attending 7 sieges; was at the siege of
Oporto, being one of the military reporters under Lord William
Russell. Appointed to the Lieutenant-Colonelcy of the 15th
Hussars, March 21st, 1834; appointed Brigadier-General of the
cantonment of Bangalore, 1841, and Major-General in India,
September, 1841; gazetted to the command of the Hyderabad
subsidiary force, February 15th, 1847, and took command March
3rd, at Secunderabad; appointed Major-General in 1854, and
Colonel of the 12th Lancers, 29th November, 1856. Sir Lovell
Benjamin Lovell received the war medal, with eleven clasps, for
Busaco, Fuentes d’Onor, Badajoz, Salamanca, Vittoria, the
Pyrenees, Nive, Orthes, and Toulouse. He died at Brighton in
1861. Sir Lovell and his brother assumed by sign manual the
surname and arms of Lovell in 1840.
[J] Prince Lippe Bückeburg.
[K] During our stay in Altea Bay, in 1812, I was invited by the
Spanish authorities in the town to assist at the proclaiming of the
new constitution, and accordingly landed my officers and marines
to be present at the ceremony of reading them. A few of the
Spaniards cheered, as well as ourselves, and called out, “Viva
Fernando Septimo;” but it appeared to me they were not very
enthusiastic about it at that period; indeed they did not seem to
care two straws whether they had the old or new constitution—to
get rid of the French was the first object.
[L] (!) Peaks.
[M] Amongst so many new black freemen in the West Indies, of
course many cases of delinquency must occur. Why not transport
all troublesome and bad characters to Africa? They originally
came from thence, and it would be only returning them back to
their own country. Just land them on the beach at Bonny, and
leave them to find their own way amongst their countrymen, or
send them to Fernando Po to clear the forests and make roads,
which would ventilate the island and make it more healthy.
[N] Medals were given in 1848(?) for the Peninsula wars, and to
the survivors of the Battle of Trafalgar also in 1848. An English
merchant, whose name I cannot remember, gave to some of
those who were present at the Battle of Trafalgar (among the
fortunate recipients was my father) medals, having on one side
the profile of Lord Nelson, and on the reverse side the
representation of the ships going into action, with the date,
October 1st, 1804, and round it the memorable words signalled to
the fleet: “England expects every man will do his duty.” This
medal is much prized by the family, as is also the dirk previously
mentioned. (M.S.L.)
[O] The revilers of our American mode of warfare should bear in
mind other circumstances, viz.: that America seized the
opportunity of declaring war against us at a most critical period,
when we were not only making a desperate struggle for our
existence as a nation, but also to liberate other powers from the
iron grasp of Bonaparte, and fighting in the cause of liberty itself.
That must not be forgotten on our side of the question.
[P] The rear-admiral, in the Albion, arrived on the previous
evening, when Captain Ross joined with the boats of that ship in
the attack on the fort by water.
[Q] Lieutenant-Colonel Williams, of the Marines, was not at the
capture of Washington. He was then in Canada, and joined us at
Cumberland Island previous to the attack on Fort Washington, at
Point-à-Petre.
Transcriber's Note:
The following is a list of changes made to the original. The first line is the original line,
the second the corrected one.
Page 108
We remained at O’Rodonto three days, during
We remained at O’Rodondo three days, during
northward to invest Cuidad Rodrigo.
northward to invest Ciudad Rodrigo.
Operations against Cuidad Rodrigo having been
Operations against Ciudad Rodrigo having been
Page 110
was ordered to cover the siege of Cuidad Rodrigo.
was ordered to cover the siege of Ciudad Rodrigo.
Page 114
nexts attracts attention. This was founded about
next attracts attention. This was founded about
Page 124
4th July, sent me to Palma Bay, Minorca, to collect
4th July, sent me to Palma Bay, Majorca, to collect
Page 138
Invincible, thinking it advisable to make a reconnoissance
Invincible, thinking it advisable to make a reconnaissance
Page 183
of the Eudymion (50), Captain Henry Hope, that
of the Endymion (50), Captain Henry Hope, that
*** END OF THE PROJECT GUTENBERG EBOOK PERSONAL
NARRATIVE OF EVENTS, FROM 1799 TO 1815 ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like