Sockets are byte streams, not message streams
The first time you try to write a network client or server directly on top of sockets, you do something like this:
for filename in filenames: with open(filename, 'rb') as f: sock.sendall(f.read())
And then, on the other side:
for i in count(0): msg = sock.recv(1<<32) if not msg: break with open('
Why you don't want to dynamically create variables
(Someone pointed out to me that Ned Batchelder has a similar post called Keep data out of your variable names.
7Why eval/exec is bad
Novices to Python often come up with code that tries to build and evaluate strings, like this:
for name in names: exec('{} = {}'.format(name, 0))
… or this:
exec('def func(x): return {} * x**2 + {} * x + {}'.format(a, b, c)) return func
99% of the time, this is a problem you shouldn't be solving
Iterator Pipelines
If you look at the major changes in Python 3, other than the Unicode stuff, most of them are about replacing list-based code with iterator-based code.
2Why are non-mutating algorithms simpler to write in Python?
Let's say you've got the list [-10, 3, -2, 14, 5], and you want the list filtered to just the non-negative values.
2