Improved python regenerate script