1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| def changetext(dir,a,b): with open(dir, 'r', encoding='utf-8') as f: lines = [] for line in f.readlines(): if line != '\n': lines.append(line) f.close() with open(dir, 'w', encoding='utf-8') as f: for line in lines: if a in line: line = b f.write('%s\n' % line) else: f.write('%s' % line) if __name__=='__main__': penetrate_ratio = [5,10,15,20,30,40] manage_lane_type = ['base - fair','softMLinline','strongMLinLine','strongMLoutline'] peak_type=['peak','sub-peak'] for p in penetrate_ratio: for item_ml in manage_lane_type: for k in peak_type: dir = "C:\\Users\\Run\\Desktop\\毕设仿真\\veryFair\\"+str(item_ml)+"\\"+k+"\\"+str(p)+"\\simu_model.inpx" changetext(dir,'<speedDistributionDataPoint fx="0.000000" x="85.000000"/>', '\t\t\t\t<speedDistributionDataPoint fx="0.000000" x="60.000000"/>') changetext(dir,'<speedDistributionDataPoint fx="0.070822" x="95.687023"/>', '\t\t\t\t<speedDistributionDataPoint fx="0.10610000" x="75.000000"/>') changetext(dir,'<speedDistributionDataPoint fx="0.274788" x="103.893130"/>', '\t\t\t\t<speedDistributionDataPoint fx="0.1950000" x="80.000000"/>') changetext(dir,'<speedDistributionDataPoint fx="0.793201" x="114.484733"/>', '\t\t\t\t<speedDistributionDataPoint fx="0.26260000" x="85.000000"/>') changetext(dir,'<speedDistributionDataPoint fx="0.954674" x="121.259542"/>', '\t\t\t\t<speedDistributionDataPoint fx="0.41410000" x="95.000000"/>') changetext(dir,'<speedDistributionDataPoint fx="1.000000" x="135.000000"/>', '\t\t\t\t<speedDistributionDataPoint fx="0.59090000" x="100.000000"/>\n\t\t\t\t<speedDistributionDataPoint fx="0.88380000" x="105.000000"/>\n\t\t\t\t<speedDistributionDataPoint fx="1.0000" x="110.000000"/>')
|