Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///
- * ABC Names
- A-06,B-18,
- * Data
- 1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
- 1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
- 2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-01,-6.844e-02,-4.139e-02, 9.502e-02,
- 1.981e-01, 1.937e-01, 2.336e-01, 1.617e-01,-4.240e-02, 2.285e-02, 1.878e-02, 1.064e-01,
- 9.562e-02, 6.727e-02, 1.135e-01, 6.765e-02,-7.850e-02, 6.711e-02, 1.317e-02, 8.367e-02,
- * Starting position
- -.5000E+01
- ///
- 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])>5:
- print key, ": array of %i entries"%len(data_dict[key])
- else:
- print key, ": ", data_dict[key]
- startingPosition = float(data_dict["Starting position"][0])
- data_list_of_floats = map(float, data_dict["Data"])
- startingPosition = float(data_dict["Starting position"][0])
- data_list_of_floats = map(float, data_dict["Data"])
- f = open("abc.txt")
- all_lines = f.readlines()
- f=0
- for line in open("file"):
- line=line.strip()
- if "Starting" in line:
- f=0
- if "Data" in line:
- f=1
- continue
- if f:
- print line
- {'a':['line1','line2'],'b':['line1'],'c':['line1','line2','line3']}
- block_names = ['b','a','c']
- for line in open('file.txt'):
- block_dict = {} #dict to populate with lists of lines
- block = [] # dummy block in case there is data or lines before first block
- ck_nm = [blk_nm for blk_nm in block_names if line.startswith(blk_nm)] #search block names for a match
- if ck_nm: # did we find a match?
- block_dict[ck_nm[0]] = block = [] # set current block
- else:
- block.append(line) #..or line.split(',') ..however you want to parse the data
- data = [
- 1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
- 1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
- 2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-01,-6.844e-02,-4.139e-02, 9.502e-02,
- 1.981e-01, 1.937e-01, 2.336e-01, 1.617e-01,-4.240e-02, 2.285e-02, 1.878e-02, 1.064e-01,
- 9.562e-02, 6.727e-02, 1.135e-01, 6.765e-02,-7.850e-02, 6.711e-02, 1.317e-02, 8.367e-02,
- ]
Add Comment
Please, Sign In to add comment