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 sys | |
| def my_excepthook(exc_type, exc_value, tb): | |
| print 'My Excepthook:' | |
| # traceback display: see tb_printinternal from cpython source | |
| print ' Traceback (most recent call last):' | |
| while tb: | |
| filename = tb.tb_frame.f_code.co_filename | |
| name = tb.tb_frame.f_code.co_name |
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 gc | |
| class A(): | |
| # For Python, finalizers means instance objects with __del__ methods. | |
| def __del__(self): | |
| pass | |
| print gc.garbage | |
| # [] |
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 A(): | |
| ... val = 0 | |
| ... | |
| >>> a = A() | |
| >>> a.val, a = 1, a.val # right | |
| >>> a = A() | |
| >>> a, a.val = a.val, 1 # wrong | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| AttributeError: 'int' object has no attribute 'val' |
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 test(a, b): | |
| ... print a, b | |
| ... | |
| >>> test('hello', 'world') | |
| hello world | |
| >>> test(*('hello', 'world')) # tuple | |
| hello world | |
| >>> test(*iter(['hello', 'world'])) # iter | |
| hello world | |
| >>> test(*['hello', 'world']) # list |
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
| numbers: | |
| :%s/[0-9]\+/<something>/gc | |
| strings: | |
| :%s/[a-zA-Z]\+/<something>/gc | |
| parentheses: | |
| :%s/[\[\]{}()<>]\+/<something>/gc | |
| special characters: |
NewerOlder