<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(self,new_filename,update_regul=True,version=None):
 """main entry point to write a pest control file. Parameters new_filename : str name of the new pest control file update_regul : (boolean) flag to update zero-order Tikhonov prior information equations to prefer the current parameter values version : int flag for which version of control file to write (must be 1 or 2). if None, uses Pst._version, which set in the constructor and modified during the load """

        if version is None:
            version = self._version

        if version == 1:
            return self._write_version1(new_filename=new_filename,update_regul=update_regul)
        elif version == 2:
            return self._write_version2(new_filename=new_filename, update_regul=update_regul)
        else:
            raise Exception("Pst.write() error: version must be 1 or 2, not '{0}'".format(version))