Python reg function