<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def setNetworkKey(self, key):
 """set Thread Network master key Args: key: Thread Network master key used in secure the MLE/802.15.4 packet Returns: True: successful to set the Thread Network master key False: fail to set the Thread Network master key """

        masterKey = ''
        print '%s call setNetworkKey' % self.port

        try:
            if not isinstance(key, str):
                masterKey = self.__convertLongToString(key)

                # prpend '0' at the beginning
                if len(masterKey) < 32:
                    masterKey = masterKey.zfill(32)

                cmd = WPANCTL_CMD + 'setprop Network:Key %s' % masterKey
                datasetCmd = WPANCTL_CMD + 'setprop Dataset:MasterKey %s' % masterKey
            else:
                masterKey = key
                cmd = WPANCTL_CMD + 'setprop Network:Key %s' % masterKey
                datasetCmd = WPANCTL_CMD + 'setprop Dataset:MasterKey %s' % masterKey

            self.networkKey = masterKey
            self.hasActiveDatasetToCommit = True
            return self.__sendCommand(cmd)[0] != 'Fail' and self.__sendCommand(datasetCmd)[0] != 'Fail'
        except Exception, e:
            ModuleHelper.WriteIntoDebugLogger('setNetworkkey() Error: ' + str(e))