Python: several fixes
This is a squash commit of the joint work from: * Jan Tojnar (@jtojnar) * Linus Heckemann (@lheckemann) * Ryan Mulligan (@ryantm) * romildo (@romildo) * Tom Hunger (@teh)