Start reading Guide to: Learning Python Decorators on the free Kindle Reading App or on your Kindle in under a minute. Don't have a Kindle? Get your Kindle here.
Programming Books C Java PHP Python Learn more Browse Programming Books

Deliver to your Kindle or other device

Enter a promotion code
or gift card
 
 
 

Try it free

Sample the beginning of this book for free

Deliver to your Kindle or other device

Sorry, this item is not available in
Image not available for
Color:
Image not available

To view this video download Flash Player

 

Guide to: Learning Python Decorators [Kindle Edition]

Matt Harrison
4.5 out of 5 stars  See all reviews (23 customer reviews)

Print List Price: $8.97
Kindle Price: $4.99
You Save: $3.98 (44%)

Free Kindle Reading App Anybody can read Kindle books—even without a Kindle device—with the FREE Kindle app for smartphones, tablets and computers.

To get the free app, enter your email address or mobile phone number.

Formats

Amazon Price New from Used from
Kindle Edition $4.99  
Paperback $8.07  
Shop the new tech.book(store)
New! Introducing the tech.book(store), a hub for Software Developers and Architects, Networking Administrators, TPMs, and other technology professionals to find highly-rated and highly-relevant career resources. Shop books on programming and big data, or read this week's blog posts by authors and thought-leaders in the tech industry. > Shop now

Book Description

Do you want to take your Python to the next level?
Python is easy to learn. You can learn the basics in a day and be
productive with it. But there are more advanced constructs that you
will eventually run across if you spend enough time with it. Don't be confused by these. Learn them, embrace them, and improve your code and others.
 
Decorators
Decorators are pretty common in modern Python. While not strictly necessary, they can reduce code size while enabling control of function input, invocation and output. They also enable separation of responsibility and DRY. Many explanations of decorators are brief and leave the reader somewhat confused. This book is an attempt to remedy that. It is based off of popular tutorials given at PyCon and Python user groups. Without fail, attendees mention that "decorators now make sense". Not only do they understand decorators, but they can write them as well.
 
The guide covers:
  • Functions
  • Closures
  • *args
  • **kwargs
  • Decorating with functions
  • Decorating with classes
  • Alternate decorating methods


Write Python code like the masters
These constructs, while not necessary per se, allow you to be more succinct,
re-use code, and think about code in a different way. You will learn:
  • How the constructs work
  • When to use them
  • Real life examples from the standard library
Understand other's code
This book covers many of these intermediate constructs that are available in Python. The book covers both Python 2 and 3. Topics include:
  • In's and out's of functions
  • Closures
  • Decorators
  • Real world examples of their use
Based on popular tutorials and sessions 
I have taught material similar to these constructs at popular tutorials at conferences such as PyCon, OSCON and Strata (and other
conferences). This book is based on my experience teaching and using
Python for many years. I hope you learn something while in the course
of your reading. Maybe it will help you in your next task, code
review, or job interview.
 
Up Your Advanced Python Skills
It is assumed that the reader has some knowledge of Python. You will walk away knowing the the in's and out's of closures and decorators, when to use them, and how to use them.


Editorial Reviews

Review

Succinct, focused
This inexpensive ebook is a little gem. Matt gives tight, crystal clear explanations that I haven't found anywhere else.
- J. Adams
 
 
Cleaned up some ugly with closures today, after reading @__mharrison__'s decorators ebook.
- @MattJDarling

About the Author

Matt Harrison Matt Harrison has over 11 years Python experience across the domains of search, build management and testing, business intelligence and storage.
He has presented and taught tutorials at conferences such as SCALE, PyCON and OSCON as well as local user conferences. The structure and content of this book is based off of first hand experience teaching Python to many individuals.
He blogs at hairysun.com and occasionally tweets useful Python related information at @__mharrison__.

Product Details

  • File Size: 283 KB
  • Print Length: 45 pages
  • Simultaneous Device Usage: Unlimited
  • Sold by: Amazon Digital Services, Inc.
  • Language: English
  • ASIN: B006ZHJSIM
  • Text-to-Speech: Enabled
  • X-Ray:
  • Word Wise: Not Enabled
  • Lending: Enabled
  • Amazon Best Sellers Rank: #162,507 Paid in Kindle Store (See Top 100 Paid in Kindle Store)
  •  Would you like to give feedback on images?


Customer Reviews

Most Helpful Customer Reviews
17 of 17 people found the following review helpful
5.0 out of 5 stars Secret Decoder Ring for Advanced Python Beginners February 6, 2012
Format:Kindle Edition|Verified Purchase
Once past "hello, world!" most beginners go through a long period of monkey-see-monkey-do learning to cobble together a collection of phrases that seem to work, although you're never exactly sure why. Eventually you run up against problems that you can't find a good example for and you have to do the hard work of understanding exactly what it is that you have asked your code to do. This is the beginning of the real learning.

One of the terms that floats around is the mysterious "decorator" that never seems urgent enough to look into, although they turn out to be quite useful. If you have been meaning get around to looking into this, the Guide to Learning Python Decorators is the place to start. But that's actually not the compelling reason for most Python newcomers to pick up this book.

A common source of beginner confusion is the "scope" of variables in functions: "I've written this function and it takes some values as input and derives a result through multiple steps. I can get the final result, but not all the intermediate variables that I've set. What gives?" This and similar questions arise from confusion as to when names are available within a function definition and when they are available to other functions and statements. It's sort of like trying to understand a language without knowing the difference between the present tense ("I am") and the past tense ("I was").

This book will clear up your confusions about functions even before you start to read about decoration at all. In addition to getting straight about scope, you'll finally get clarity about the difference between arguments and parameters, positional parameters, named parameters, etc.
Read more ›
Comment | 
Was this review helpful to you?
6 of 6 people found the following review helpful
5.0 out of 5 stars Level-up your python skills February 7, 2012
By Amjith
Format:Kindle Edition
This is a concise guide that covers all the necessary background in order to understand decorators.

Although many python programmers use decorators in their code, very few know how to write a decorator. Writing a decorator is considered an advanced skill and this book does an excellent job of demystifying it.

The book has dedicated sections to cover nested functions, variable function parameters, the * operator (*args, **kwargs) and closures, which are all advanced concepts that lead up to decorators.

This books serves as a stand-alone manual to python decorators. I'd highly recommend it for beginners and experts who are trying to level-up their python chops.
Comment | 
Was this review helpful to you?
5 of 5 people found the following review helpful
3.0 out of 5 stars Nice introduction, no advanced material February 20, 2013
Format:Kindle Edition|Verified Purchase
A clear and concise book. The author clearly explains the issue, bottom up: python functions, arguments, parameters, closures and finally decorators. The english is clear, so it's easy to understand the concept.
However, for a price of a full book, you could expect some advanced material: more about multiple decorators (which are only reminded in one page at the end), exceptions, detailed examples of common usage, class decorators etc.
Comment | 
Was this review helpful to you?
4 of 4 people found the following review helpful
Format:Kindle Edition|Verified Purchase
Recently, in a post titled "Python decorators" on the PythonConquersTheUniverse blog, I described what I think is wrong about most introductions to decorators, and I sketched out what I think is a better way to structure an introduction to decorators. In that post I wrote this:

There is an old saying to the effect that "Every stick has two ends, one by which it may be picked up, and one by which it may not." I believe that most explanations of decorators fail because they pick up the stick by the wrong end.

What I like about Matt Harrison's e-book "Guide to: Learning Python Decorators" is that it is structured in the way that I think an introduction to decorators should be structured. It picks up the stick by the proper end.

The first two-thirds of the Guide hardly talk about decorators at all. Instead, Matt begins with a thorough discussion of how Python functions work. By the time the discussion gets to decorators, we have been given a strong understanding of the internal mechanics of functions. And since most decorators are functions, at that point it is easy for Matt to explain the internal mechanics of decorators.

Which is just as it should be.

So I am happy to rate "Guide to: Learning Python Decorators" as HIGHLY RECOMMENDED.
Comment | 
Was this review helpful to you?
2 of 2 people found the following review helpful
2.0 out of 5 stars Not really much about the decorators. July 2, 2013
Format:Kindle Edition|Verified Purchase
The book isn't really about decorators.Well, it gives a very nice introduction to functions in Python. I also admit that it clearly explains the concept of closures.

But then we directly jump into the chapter about decorators. It mentions a few contexts in which decorators might be handy. The author explains how to construct decorators. And then... the book is over. It is neither a thorough study how to use the concept, nor a handful of hints...

There are many code examples in the book. Unfortunately, some are clearly wrong. It appears that the author didn't test these examples before putting them into the text.
Comment | 
Was this review helpful to you?
2 of 2 people found the following review helpful
5.0 out of 5 stars Very good March 14, 2013
Format:Kindle Edition|Verified Purchase
If you have never looked at or written python decorators before, this is a good book to go through the background of how and why they work, and a few examples of them in action.

It is a well written guide, however it did seem like just as you were getting to what would be the good detailed examples or advanced use cases the book just ended.

Edit: After having this book for a few months it has become very useful as the goto reference anytime I have to use decorators. For how much use I have gotten out of this guide it is definitely worth it.
Was this review helpful to you?
Most Recent Customer Reviews
4.0 out of 5 stars Great Decorator Explanation
This book did a great job of covering decorators.

Starts off like it should making sure you understand how functions works, and then moves to function based... Read more
Published 2 months ago by Garry Polley
4.0 out of 5 stars Discover the power Python Decorators and more ...
Overall the book served it's intended purpose to teach the reader about Python Decorators. Some knowledge of Python is assumed and I would recommend reading an introductory text... Read more
Published 3 months ago by Versalytics
5.0 out of 5 stars Five Stars
It is definitely one of the best books i have seen for learning decorators.
Published 5 months ago by Gokul
5.0 out of 5 stars Short and to the point. I finally understand this
I finally understand decorators in python and how to use them. This book makes the subject easy to understand :)
Published 8 months ago by Amazon Customer
5.0 out of 5 stars Excellent Book for Beginners
I'm a beginner Python developer and this book was easy to understand because it went over concepts in a good order. Read more
Published 8 months ago by Mely
5.0 out of 5 stars Easy to understand and contains best practices
I've gotten by just making decorators work but Matt's book helped me up my game and write them better. Thanks Matt!
Published 11 months ago by Paul Hildebrandt
4.0 out of 5 stars Consider Matt's larger book
Consider instead "Treading on Python Volume 2: Intermediate Python" which contains this booklet, along with two of Matt's other booklets.
Published 13 months ago by G. Wideman
4.0 out of 5 stars Technical, concise, simple
I am not a programmer and just learned python for fun. I found this book as a good way to learn a little more in simple language and with simple examples. Read more
Published 14 months ago by Pablo Balerio
5.0 out of 5 stars Great Book
Easy to learn from theese examples
twenty more words required here, now fifteen more required here, now ten more required here, now five more required here
Published 14 months ago by Thomas M Bennett
5.0 out of 5 stars Succinct, focused.
This inexpensive ebook is a little gem. Matt gives tight, crystal clear explanations that I haven't found anywhere else. Read more
Published 17 months ago by J. Adams
Search Customer Reviews
Search these reviews only

More About the Author

Matt Harrison has over 10 years Python experience across the domains of search, build management and testing, business intelligence and storage.

He has presented and taught tutorials at conferences such as SCALE, PyCON and OSCON as well as local user groups. In addition he has been a private tutor teaching programming to teenagers as well as retired folk. The structure of his books are based off of his first hand experience teaching Python to many individuals.

What Other Items Do Customers Buy After Viewing This Item?


Forums

There are no discussions about this product yet.
Be the first to discuss this product with the community.
Start a new discussion
Topic:
First post:
Prompts for sign-in
 


Look for Similar Items by Category