Luciano Ramalho
Fluent
Python
CLEAR, CONCISE, AND EFFECTIVE PROGRAMMING
PROGRAMMINGPYTHON
Fluent Python
ISBN: 978-1-491-9-46008
US $49.99 CAN $57.99
“
I am proud to have been
a tech reviewer for this
excellent book—not only
will it help many
intermediate Python
programmers on their
road towards mastery,
but it has taught me quite
a few things, too!
”
—Alex Martelli
Python Software Foundation Fellow
“
Fluent Python is a
treasure trove full of
useful programming
tricks for intermediate to
advanced Python coders
who want to push the
boundaries of their
knowledge.
”
—Daniel and Audrey Roy Greenfeld
authors of Two Scoops of Django
Twitter: @oreillymedia
facebook.com/oreilly
Python’s simplicity lets you become productive quickly, but this often means
you aren’t using everything it has to oer. With this hands-on guide, you’ll learn
how to write effective, idiomatic Python code by leveraging its best—and
possibly most neglected—features. Author Luciano Ramalho takes you
through Python’s core language features and libraries, and shows you how to
make your code shorter, faster, and more readable at the same time.
Many experienced programmers try to bend Python to fit patterns they
learned from other languages, and never discover Python features outside
of their experience. With this book, those Python programmers will
thoroughly learn how to become proficient in Python 3.
This book covers:
■ The Python data model: understand how special methods are
the key to the consistent behavior of objects
■ Data structures: take full advantage of built-in types, and
understand the text versus bytes duality in the Unicode age
■ Functions as objects: view Python functions as rst-class objects,
and understand how this aects popular design patterns
■ Object-oriented idioms: build classes by learning about
references, mutability, interfaces, operator overloading, and
multiple inheritance
■ Control ow: leverage context managers, generators,
coroutines, and concurrency with the concurrent.futures and
asyncio packages
■ Metaprogramming: understand how properties, attribute
descriptors, class decorators, and metaclasses work
Luciano Ramalho, a Python programmer since 1998, is a Python Software
Foundation fellow, co-owner of Python.pro.br—a training company in Brazil—
and cofounder of Garoa Hacker Clube, Brazil’s first hackerspace. He has led
software development teams and taught Python courses in Brazilian media,
banking, and government sectors.
Luciano Ramalho
Boston
Fluent Python
Fluent Python
by Luciano Ramalho
Copyright © 2015 Luciano Gama de Sousa Ramalho. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com.
Editors: Meghan Blanchette and Rachel Roumeliotis
Production Editor: Melanie Yarbrough
Copyeditor: Kim Cofer
Proofreader: Jasmine Kwityn
Indexer: Judy McConville
Cover Designer: Ellie Volckhausen
Interior Designer: David Futato
Illustrator: Rebecca Demarest
August 2015:
First Edition
Revision History for the First Edition:
2015-07-24: First release
2015-08-21: Second release
See http://oreilly.com/catalog/errata.csp?isbn=9781491946008 for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Fluent Python, the cover image, and
related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and author have used good faith efforts to ensure that the information and instructions
contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or
omissions, including without limitation responsibility for damages resulting from the use of or reliance on
this work. Use of the information and instructions contained in this work is at your own risk. If any code
samples or other technology this work contains or describes is subject to open source licenses or the intel‐
lectual property rights of others, it is your responsibility to ensure that your use thereof complies with such
licenses and/or rights.
ISBN: 978-1-491-94600-8
[LSI]
Para Marta, com todo o meu amor.