AndreMicheletti / decorator-examples

Some decorator examples in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

decorator-examples

See here some decorator implementation examples in Python 3.6

Decorators

  • line_profiler Profile the function line-by-line

  • require_login Exit the function depending on the return of another function

  • ensure_file Ensure the file exists, and if not create it

  • ensure_file2 Same as before, but more flexible

  • string_format Make sure that all string arguments passed to a function are formatted the same way

  • cached Cache the result of functions to reduce CPU time

  • timer Create a timer to track the time spent on the function call

  • profile_and_save Same as before, but maintaining a history in a .json file

Tests

Here are the results of the tests in the file end

call to large_function took 1.100401 seconds
call to large_function took 0.000000 seconds
a
b
d
ef
f
g

About

Some decorator examples in Python


Languages

Language:Python 100.0%