if [hex, bytes, bytes_le, fields, int].count(None) != 4:!
raise TypeError('need exactly one argument')!
Slide 27
Slide 27 text
if [hex, bytes, bytes_le, fields, int].count(None) != 4:!
raise TypeError('need exactly one argument')!
Slide 28
Slide 28 text
if (!
(hex is None) + (bytes is None) + (bytes_le is None) +!
(fields is None) + (int is None)!
) != 4:!
raise TypeError!
Slide 29
Slide 29 text
Python makes
everything easier
Slide 30
Slide 30 text
Let’s talk about strings
Slide 31
Slide 31 text
char *data = malloc(1025);!
while (true) {!
size_t n = read(fd, data, 1024);!
data[n] = '\0';!
char *start = data;!
while (start < data + n) {!
if (isspace(*start)) {!
break;!
}!
start++;!
}!
printf("%s\n", start);!
}!
Slide 32
Slide 32 text
while True:!
data = os.read(fd, 1024)!
print data.lstrip()!
Slide 33
Slide 33 text
Zero Buffer
Slide 34
Slide 34 text
from zero_buffer import Buffer!
!
b = Buffer.allocate(8192)!
with open(path, "rb") as f:!
b.read_from(f.fileno())!
for part in b.view().split(b":"):!
part.write_to(sys.stdout.fileno())!
sys.stdout.write('\n')!
A few more myths
• Functions calls are really expensive
• Using only builtin data types will make your code
fast
• Don’t write Python in the style of Java or C