I am trying to develop a function for my application which would use already opened file (fin) and read certain line from it. Each line in the text starting from given keywords (pos1). Finally this function should return a print of all line containing the keywords pos1. But apparently "linecache" return only space.
Do somebody know a way to deal with line in the text file differently or know a solution to my problem with linecache? Thank Beforehand!!!
def CifT(self):
import linecache
global fin #opened file
start = 1.0
pos1 = ["_chemical_formula_moiety", "_chemical_formula_weight", "_symmetry_cell_setting",
"_symmetry_space_group_name_H-M ", "_cell_length_a","_cell_length_b", "_cell_length_c", "_cell_angle_alpha",
"_cell_angle_beta", "_cell_angle_gamma", "_cell_volume", "_cell_formula_units_Z", "_cell_measurement_temperature",
"_cell_measurement_theta_min", "_cell_measurement_theta_max", "_exptl_absorpt_coefficient_mu", "_diffrn_radiation_type",
"_refine_ls_R_factor_all", "_refine_ls_R_factor_gt", "_refine_ls_wR_factor_ref", "_refine_ls_wR_factor_gt", "_refine_ls_goodness_of_fit_ref"]
for i in pos1:
while 1:
pos = self.text.search(i, start, stopindex=END)
if not pos:
break
print pos[:2] #print a number of line for each keyword
line=linecache.getline("fin", pos:2) #read line
print line
start = pos + "+1c"