Skip to content

Comment on Introduction to Python Decoratorsparent

Comments

a good example, when working with the Jinja2 templating language, when you want to declare your own modifier, a function that's called within the templating language like {bit of text|awesomify}, you'd just need to write a function with a decorator on it, like

    @jinja2_modifier
    def awesomify(s):
        return "%s is awesome" % s
(except it wasn't "jinja2_modifier", look it up in the docs)
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.