def loadFromFile(self, filename):
		"""
		Reads a list of parameters from file. Returns whether it has succeeded
		in doing so.

		:type filename: basestring
		:rtype: bool
		"""
		directory, lastPathComponent = os.path.split(filename)
		self.name = lastPathComponent

		# TODO: write tests for this method in order to better specify its behaviour
		noErrors = True
		try:
			if filename.startswith('.DS'):
				noErrors = False
			else:
				with open(filename, "r") as parameterFile:
					try:
						for line in parameterFile:
							param = Parameter.parameterFromString(line)
							if param:
								self.append(param)

					except Exception:
						noErrors = False
		except Exception:
			noErrors = False
			
		return noErrors
示例#2
0
    def loadFromFile(self, filename):
        """
		Reads a list of parameters from file. Returns whether it has succeeded
		in doing so.

		:type filename: basestring
		:rtype: bool
		"""
        directory, lastPathComponent = os.path.split(filename)
        self.name = lastPathComponent

        # TODO: write tests for this method in order to better specify its behaviour
        noErrors = True
        try:
            if filename.startswith('.DS'):
                noErrors = False
            else:
                with open(filename, "r") as parameterFile:
                    try:
                        for line in parameterFile:
                            param = Parameter.parameterFromString(line)
                            if param:
                                self.append(param)

                    except Exception:
                        noErrors = False
        except Exception:
            noErrors = False

        return noErrors