def TestListParsing(): List1 = ['1', '1.1', '2'] List2 = ['1', '1a', '2'] List3 = ['1', '2', '3'] joe1 = LSDost.ParseListToType(List1) joe2 = LSDost.ParseListToType(List2) joe3 = LSDost.ParseListToType(List3) print "Type of 1 is: " print type(joe1[0]) print "Type of 2 is: " print type(joe2[0]) print "Type of 3 is: " print type(joe3[0])
def __init__(self, FileName): # This gets the filename without the .csv file_prefix = LSDOst.GetFilePrefix(FileName) self.FilePrefix = file_prefix print "The object file prefix is: " + self.FilePrefix #See if the parameter files exist if os.access(FileName, os.F_OK): this_file = open(FileName, 'r') lines = this_file.readlines() # get rid of the control characters this_line = LSDOst.RemoveEscapeCharacters(lines[0]) # Now get a list with the names of the parameters self.VariableList = [] TestList = this_line.split(',') for name in TestList: this_name = LSDOst.RemoveEscapeCharacters(name) self.VariableList.append(this_name.lower()) print "Variable list is: " print self.VariableList # get rid of the names del lines[0] # now you need to make a dict that contains a list for each varaible name DataDict = {} TypeList = [] for name in self.VariableList: DataDict[name] = [] # now get the data into the dict #firstline = True for line in lines: this_line = LSDOst.RemoveEscapeCharacters(line) split_line = this_line.split(',') for index, name in enumerate(self.VariableList): this_var = LSDOst.RemoveEscapeCharacters(split_line[index]) #this_variable = LSDOst.ParseStringToType(this_var) DataDict[name].append(this_var) # now go back and get the correct type DataDictTyped = {} for name in self.VariableList: this_list = DataDict[name] typed_list = LSDOst.ParseListToType(this_list) DataDictTyped[name] = typed_list TypeList.append(type(typed_list[0])) self.PointData = DataDictTyped self.DataTypes = TypeList else: print "Uh oh I could not open that file" self.VariableList = [] self.DataTypes = [] self.PointData = {} # now make sure the data has latitude and longitude entries if "latitude" not in self.VariableList: print "Something has gone wrong, latitude is not in the variable list" print "Here is the variable list: " print self.VariableList if "longitude" not in self.VariableList: print "Something has gone wrong, longitude is not in the variable list" print "Here is the variable list: " print self.VariableList # Add the latitude and longitude to their own data members and get rid # of those from the VariableList self.Latitude = self.PointData["latitude"] self.Longitude = self.PointData["longitude"]