Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a complete guess at some code that might load the type of file this is an example of, but which should be a little robust: </p> <pre><code>f = open("mdata.txt") data_dict = {} section = None data_for_section = "" for line in f: line = line.strip() #remove whitespace at start and end if section != None and (line[0] == "*" or line == "///"): # if we've just finished a section, put whatever we got into the data dict data_dict[section] = [bit for bit in data_for_section.split(",") if bit != ""] if line[0] == "*": # "*" denotes the start of a new section, probably, so remember the name section = line [2:] data_for_section = "" continue data_for_section += line f.close() #got the data, now for some output print "loaded file. Found headings: %s"%(", ".join(data_dict.keys())) for key in data_dict.keys(): if len(data_dict[key])&gt;5: print key, ": array of %i entries"%len(data_dict[key]) else: print key, ": ", data_dict[key] </code></pre> <p>which outputs for your file:</p> <pre>loaded file. Found headings: ABC Names, Data, Starting position ABC Names : ['A-06', 'B-18'] Data : array of 40 entries Starting position : ['-.5000E+01']</pre> <p>of course, you'd probably want to convert the list of data strings to floating point numbers in the case of data and starting position:</p> <pre><code>startingPosition = float(data_dict["Starting position"][0]) data_list_of_floats = map(float, data_dict["Data"]) </code></pre> <p>But as to the ABC Names and how they combine with the rest of the file, we'd need some more information for that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload