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()
Short but amazing (at least for me) intro to network programming.
We start by opening two terminals: for python and netcat utility.
#Python
Few ways to merge N dicts:
# new_dct = {}; d1 = {'a': 1}; d2 = {'b': 2}
>> map(new_dct.update, [d1, d2])
>> new_dct
{'a': 1, 'b': 2}
#Python
Don't do this:
def hi():
print(‘hello’)
def fraud():
print(‘bye’)
hi.__code__ = fraud.__code__
hi()
.... bye
#Python
`==` comes before `,` :
>> (1,) == 1
False # tuple not eq. to int
And the final answer is
(False,) # prev. expression and comma
Can you guess result of this expression?
>> (1,) == 1,
#Python
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
Answer:
`TypeError: unorderable types: list() <= int()`
Interestingly
>> x[x==1]
1
Indexing:
>> x[False] # x[0]
1
>> x[True] # x[1]
2
TwittingPython retweeted
#Django 2.0 (now on master) will not support #Python 2: github.com/django/django/pul… github.com/django/django/pul… 🎉🍾✨😃
Question: what kind of error it will produce?
>> x = [1,2,3,4,5]
>> x[x<=1]
#Python
you can be surprised by result of that:
>> False is False is False
??
#Python
Function without body (noop) can be created by putting inside:
pass
""" docstring """
... (ellipsis)
#Python


