The Functools Module

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024
  • Are you ready to power up your Python skills? The Python programming language has more than 200 modules in its standard library. In this tutorial, you will learn about functools, a module that is tailor-made for acting on or returning other modules.
    You will learn about how to use functool decorators effectively, caching, function overloading and more!
    Speaker: Mike Driscoll
    Mike has been a Python developer for over a decade. He has been writing about Python for many years on his blog, The Mouse vs the Python. He has recently restarted his Python RUclips channel too. His readers got him interested in writing books about Python and now Mike has ten books published!

Комментарии • 7

  • @NicolasChanCSY
    @NicolasChanCSY 2 года назад +6

    0:00 Video starts
    0:12 Webinar began
    1:30 Speaker began his presentation
    ====================
    2:28 The `functools` module
    3:43 Caching
    4:14 `functools.cache`
    5:00 Code example 1
    6:25 Code example 2
    8:07 `functools.lru_cache`
    8:12 Code example
    11:41 `functools.total_ordering`
    12:45 Code example
    15:28 `functools.partial`
    15:50 Code example 1
    17:05 Code example 2 (featuring tkinter)
    19:17 Code example 3 (featuring wxPython)
    22:06 `functools.reduce`
    24:23 Code example
    26:08 `functools.singledispatch`
    27:37 Code example
    33:12 Honourable mentions of `plum` and `multipledispatch`
    34:50 `functools.wraps`
    35:07 Code example
    39:00 Wrapping up
    ====================
    39:45 Q&A Session
    39:58 Question 1: Compatibility with PyPy?
    41:09 Question 2: Using `cache` and `lru_cache` in async functions?
    42:40 Question 3: Any issue with `lru_cache`'s `maxsize`?
    43:35 Clarification on Question 1: Speed difference between PyPy vs CPython with functools caching?
    44:28 Question 4: Organise dispatched functions into a class?
    47:00 Conclusion
    Please feel free to point out any mistakes.
    Thanks for the webinar.

  • @TheMako101
    @TheMako101 11 месяцев назад

    Great tutorial! Explains some fairly complex topics very clearly and with easy-to-understand examples. Thank you, Mike :)

  • @NicolasChanCSY
    @NicolasChanCSY 2 года назад +1

    `functools.cache_property` was mentioned in table of contents but not discussed further? Or did I missed it?

  • @kcvinu
    @kcvinu Год назад

    I tried "@cache" with some win32 api code. It prevents me from using the "DeleteObject()" function. I think it is caching the gdi objects also. I tested this with a function which draws the gradient background color for a window. And surprisingly, I couldn't see any speed improvements. It tool around 1-3 milliseconds with @cache and without @cache

    • @6d347277696e
      @6d347277696e Год назад +2

      DeleteObject() sounds like a side-effect. If you want to use something like that you will need to implement the caching for yourself. The decorator @cache is intended for pure functions only, and like the documentation says: "it doesn’t make sense to cache functions with side-effects" (from the documentation of functools.lru_cache).

    • @kcvinu
      @kcvinu Год назад

      @@6d347277696e Got it. Thanks.

  • @TheGroundskeeper
    @TheGroundskeeper 2 месяца назад

    This is the least immersive, round about, poor quality, slow paced wreck to ever offer itself as a python tutorial. Awful.