<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def attach(self, num_name, write=0):
 """Open an existing vgroup given its name or its reference number, or create a new vgroup, returning a VG instance for that vgroup. Args:: num_name reference number or name of the vgroup to open, or -1 to create a new vgroup; vcreate() can also be called to create and name a new vgroup write set to non-zero to open the vgroup in write mode and to 0 to open it in readonly mode (default) Returns:: VG instance for the vgroup An exception is raised if an attempt is made to open a non-existent vgroup. C library equivalent : Vattach """


        if isinstance(num_name, bytes):
            num = self.find(num_name)
        else:
            num = num_name
        vg_id = _C.Vattach(self._hdf_inst._id, num,
                           write and 'w' or 'r')
        _checkErr('vattach', vg_id, "cannot attach Vgroup")
        return VG(self, vg_id)