Python trivia and all the small things I find interesting. Appreciate comments.

Joined September 2016
And here you are: with opened connection, listening on a port, sending bytes, including some newline stuff
Terminal N2 - start listening to arbitrary port $ netcat -l 1234 T1 - connect to it, and send >> s.connect(('', 1234)) >> s.send(b'abc\n')
Terminal N1 -- create a socket, the place where bytes will go to >> import socket >> s = socket.socket()
Also, for only two dicts merge: >> {**dict_a, **dict_b}
or >> reduce(lambda acc, d: dict(acc, **d), [d1, d2])
Don't do this: def hi(): print(‘hello’) def fraud(): print(‘bye’) hi.__code__ = fraud.__code__ hi() .... bye #Python
or we can look at it this way >> 2==2 , 3 (True, 3)
`==` comes before `,` : >> (1,) == 1 False # tuple not eq. to int And the final answer is (False,) # prev. expression and comma
Ways to represent number in hex (`ff`): >> hex(255).lstrip('0x') >> '{:02x}'.format(255) >> format(255, '02x') #Python
Mystery solved. David Beazley on how he did slides for talks like youtube.com/watch?v=j6VSAsKA… Answer here: forum.dabeaz.com/t/how-to-mo… #Python
It works like ternary, e.g. 1 < x < 3
Answer: `TypeError: unorderable types: list() <= int()` Interestingly >> x[x==1] 1 Indexing: >> x[False] # x[0] 1 >> x[True] # x[1] 2
Function without body (noop) can be created by putting inside: pass """ docstring """ ... (ellipsis) #Python