This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Version 3 | |
| def print_before2(label): | |
| def decorator(func): | |
| @functools.wraps(func) | |
| def wrapped(*args, **kwds): | |
| print(label, func.__name__, args, kwds) | |
| return func(*args, **kwds) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # WRONG | |
| def print_before(func, label): | |
| @functools.wraps(func) | |
| def wrapped(*args, **kwds): | |
| print(label, func.__name__, args, kwds) | |
| return func(*args, **kwds) | |
| return wrapped | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import functools | |
| def print_before(func): | |
| @functools.wraps(func) | |
| def wrapped(*args, **kwds): | |
| print(func.__name__, args, kwds) | |
| return func(*args, **kwds) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @print_before | |
| def important(lives, money, valuables=None): | |
| """Do big, important things!!""" | |
| pass | |
| >>> important(23, 105.17, valuables=['dogs']) | |
| important (23, 105.17) {'valuables': ['dogs']} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def print_before(func): | |
| def wrapped(*args, **kwds): | |
| print('Before:', func.__name__, args, kwds) | |
| return func(*args, **kwds) | |
| return wrapped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fp = open(filename, 'w') | |
| json.dump(data, fp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CPU[| 0.4%] Tasks: 40, 53 thr; 1 running | |
| Mem[||||||||||||||||||||||||||||||||||||||||||||||||||||||||338M/985M] Load average: 0.03 0.03 0.00 | |
| Swp[ 0K/0K] Uptime: 00:31:48 | |
| PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command | |
| 1001 mysql 20 0 1134M 175M 14576 S 0.0 17.8 0:00.00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid | |
| 1002 mysql 20 0 1134M 175M 14576 S 0.0 17.8 0:00.04 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid | |
| 1003 mysql 20 0 1134M 175M 14576 S 0.0 17.8 0:00.14 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ pip install -r pip-req.txt | |
| Collecting nose>=1.3.0 | |
| Using cached https://files.pythonhosted.org/packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl | |
| Collecting tox>=1.6.1 | |
| Downloading https://files.pythonhosted.org/packages/77/a7/a5b721d9bf955edfe36013e5ecc9136fc6b2fef622ab1797ff0560273d8e/tox-3.14.3-py2.py3-none-any.whl (80kB) | |
| |ββββββββββββββββββββββββββββββββ| 81kB 1.7MB/s | |
| Processing /Users/tom/Library/Caches/pip/wheels/b0/eb/ac/80e48148e00b449d5f2b60478c31f1e0fb5ec45b04950e800f/coverage-5.0.3-cp38-cp38-macosx_10_9_x86_64.whl | |
| Collecting pylint>=1.1.0 | |
| Downloading https://files.pythonhosted.org/packages/e9/59/43fc36c5ee316bb9aeb7cf5329cdbdca89e5749c34d5602753827c0aa2dc/pylint-2.4.4-py3-none-any.whl (302kB) | |
| |ββββββββββββββββββββββββββββββββ| 307kB 5.1MB/s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Mutable: | |
| pass | |
| foo, bar = Mutable(), Mutable() | |
| foo.x = 1 # It's mutable! | |
| d = {foo: 'foo', bar: 'bar'} | |
| print(d[foo]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Dispatch: | |
| def monday(self): pass # Implementations here... | |
| def tuesday(self): pass | |
| def wednesday(self): pass | |
| def thursday(self): pass | |
| def friday(self): pass | |
| def saturday(self): pass | |
| def sunday(self): pass | |