-
-
Save herczy/2576165 to your computer and use it in GitHub Desktop.
A prezentation about what is wrong with Python
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
| {{{ | |
| ╻ ┏━╸┏━┓┏━┓┏┓ ┏┓ ┏━╸╺┳┓ ╺┳╸╻ ╻┏━╸ ┏━┓╻ ╻╺┳╸╻ ╻┏━┓┏┓╻ | |
| ┃ ┃╺┓┣┳┛┣━┫┣┻┓┣┻┓┣╸ ┃┃ ┃ ┣━┫┣╸ ┣━┛┗┳┛ ┃ ┣━┫┃ ┃┃┗┫ | |
| ╹ ┗━┛╹┗╸╹ ╹┗━┛┗━┛┗━╸╺┻┛ ╹ ╹ ╹┗━╸ ╹ ╹ ╹ ╹ ╹┗━┛╹ ╹ | |
| }}} | |
| {{{ | |
| >>> from __future__ import braces | |
| SyntaxError: not a chance (<input>, line 2) | |
| }}} | |
| {{{ | |
| >>> def fun(param=[]): | |
| ... param.append('E!') | |
| ... print param | |
| ... | |
| >>> fun(); fun(); | |
| ['E!'] | |
| ['E!', 'E!'] | |
| }}} | |
| {{{ | |
| >>> True = False | |
| >>> True | |
| False | |
| }}} | |
| {{{ | |
| >>> print('wat') | |
| wat | |
| >>> type(type) | |
| <type 'type'> | |
| >>> type(print) | |
| File "<input>", line 1 | |
| type(print) | |
| ^ | |
| SyntaxError: invalid syntax | |
| }}} | |
| {{{ | |
| >>> a = lambda: 1, 2 | |
| >>> type(a) | |
| <type 'tuple'> | |
| >>> a = lambda: (1, 2) | |
| >>> type(a) | |
| <type 'function'> | |
| }}} | |
| {{{ | |
| >>> with open('file', 'r') as f: | |
| ... while a = f.readline(): | |
| File "<input>", line 2 | |
| while a = f.readline(): | |
| ^ | |
| SyntaxError: invalid syntax | |
| }}} | |
| {{{ | |
| >>> with open('file', 'r') as f: | |
| ... for line in iter(f.readline, '\n'): | |
| ... print line | |
| }}} | |
| {{{ | |
| >>> with open('file', 'r') as f: | |
| ... for line in iter(lambda: f.readline(10), '\n'): | |
| ... print line | |
| }}} | |
| {{{ | |
| >>> class C(object): | |
| ... def f(self, param): | |
| ... print param, self | |
| >>> C.f('e', 'h') | |
| Traceback (most recent call last): | |
| File "<input>", line 1, in <module> | |
| TypeError: unbound method f() must be called with C instance as first argument (got str instance instead) | |
| }}} | |
| {{{ | |
| >>> len((1,2,3,4,5,6)) | |
| >>> Item.query.count() | |
| }}} | |
| {{{ | |
| │__abs__ __add__ __and__ │ | |
| │__call__ __cmp__ __coerce__ │ | |
| │__complex__ __contains__ __debug__ │ | |
| │__div__ __divmod__ __doc__ │ | |
| │__enter__ __eq__ __exit__ │ | |
| │__float__ __floordiv__ __ge__ │ | |
| │__get__ __getattr__ __getitem__│ | |
| │__gt__ __hash__ __hex__ │ | |
| │__import__( __index__ __init__ │ | |
| │... __getattribute__ ? │ | |
| }}} | |
| {{{ | |
| >>> import threading | |
| >>> dir(threading.Thread) | |
| ['_Thread__bootstrap', ... | |
| 'getName', 'ident', 'isAlive', 'isDaemon', | |
| 'is_alive', 'join', 'name', 'run', | |
| 'setDaemon', 'setName', 'start'] | |
| }}} | |
| {{{ | |
| >>> try: | |
| ... import cStringIO | |
| ... except: | |
| ... import StringIO | |
| }}} | |
| {{{ | |
| >>> 1.__class__ | |
| File "<stdin>", line 1 | |
| 1.__class__ | |
| ^ | |
| SyntaxError: invalid syntax | |
| >>> (1).__class__ | |
| <type 'int'> | |
| }}} | |
| {{{ | |
| >>> def x(): | |
| ... c = 0 | |
| ... def y(): | |
| ... c+=1 | |
| ... y() | |
| ... print c | |
| ... | |
| >>> x() | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| File "<stdin>", line 5, in x | |
| File "<stdin>", line 4, in y | |
| UnboundLocalError: local variable 'c' referenced before assignment | |
| >>> def x(): | |
| ... c = [0] | |
| ... def y(): | |
| ... c[0] += 1 | |
| ... y() | |
| ... print c[0] | |
| ... | |
| >>> x() | |
| 1 | |
| }}} | |
| // vim:set ft=python fdm=marker: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment