Python rewrite