Name: [171] Florian Mayer
Member: 114 months
Authored: 7 videos
Description: I'm a student from Vienna, the federal capital of Austria. Please visit `My Blog <>`_ ...

Decorators: Real World Example [ID:878] (2/3)

in series: Advanced Python

video tutorial by Florian Mayer, added 09/08

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

This second video about decorators is going to show you a real-world example on how they can be used. A decorator is marking functions as deprecated. Sorry for the abrupt end, though I went on just trying to find out how to enable line-numbers. And yes, the line-number is right.

import warnings

def deprecated(func):
    def new_func(*args, **kwargs):
        warnings.warn("This function is old", DeprecationWarning,
        return func(*args, **kwargs)
    return new_func

def i_am_old(foo, bar):
    return foo, bar

def change_doc(docstring):
    def decorator(func):
        func.__doc__ = docstring
        return func
    return decorator

#@change_doc("My super-new docstring")
def foo(bar):
    """ My old docstring """
    return bar

foo = change_doc("My super-new docstring")(foo)

if __name__ == '__main__':
    #print foo.__doc__
    print i_am_old(42, "Answer")

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 25 (since July 30th)
  • Plays in last week: 2
  • Published: 95 months ago

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>

All comments excluding tick-boxed quick-comments

8. viagra for sale Thu, 22 Jul 2010 15:05

Nice, Thanks!

7. ShewenLiny Sat, 10 Apr 2010 18:16

again a very nicq video :P good explained =D

6. anonymous Sun, 27 Sep 2009 15:48

Good work

5. anonymous Thu, 17 Sep 2009 16:36

Thank you.

A very illustrative use case

4. anonymous Sun, 19 Jul 2009 20:29

Hi Florian,

The video ended abruptly before I think you done with your presentation.

The source line calling your function printed out. Was this your intention?

It's best if you can prepare your presentation so the text remains in a fixed position on the screen, so the viewer will not lose his place in your presentation. It may be possible to eliminate previous text that is not used in the presentation. It is very difficult for the viewer when the text scrolls, especially when it scrolls right of the screen. You have the luxury of moving the screen back if you are trying to find your place, a viewer doesn't have this luxury. It's best to plan ahead and set up your environment before you are in the middle of a demonstration. Such as explaining to the viewer that this example will require functions from the warning module and then show the import before you get to the point in the presentation when you are focusing on the main thrust of your presentation. It is distracting to have to have an after though taken care of in the middle of the presentation. It is much smoother for the viewer if this planned for and taken care of upfront so the viewer can concentrate on what you are really trying to show them.


Good Luck,


; ^ >

3. anonymous Thu, 25 Sep 2008 15:39

The introduction to deprecators done in the first video was simple and brief, and I really liked the part where you compare the old way of doing decorators. Nice work! :)

I also really liked the deprecation decorator, it'll definitely be useful!

Wonderful fonts, easy to the audience's eyes.

The ShowMeDo Robot says - this video is now published, thanks for adding to ShowMeDo.

Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for Florian

Decorators: Introducing functools.wraps


maccosmeticswholesalers mac makeup pencil c 17
72 months ago


Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.