1 #读取类文件。调用类 2 from Paths_info import Paths_info 3 import string 4 t=Paths_info() 5 d=t.__dict__ 6 7 8 #def fan(dict): 9 f=open("ModelInfo.txt","r") 10 l=open("modelInfo1.txt","w") 11 for eachline in f: 12 eachline = eachline.strip() 13 eachline = eachline.split("=") 14 a=eachline[0] 15 name = a 16 b=eachline[1] 17 #根据不同的数据类型读取 18 if b.isdigit(): 19 b=string.atoi(b) 20 elif "[" in b: 21 a=[] 22 b=b.replace("["," ") 23 b=b.replace("]"," ") 24 b=b.strip().split(‘,‘) 25 for t in b: 26 if "." in t: 27 t=string.atof(t) 28 else : 29 t=string.atoi(t) 30 a.append(t) 31 b=a 32 elif "." in b: 33 c=b.replace(".","") 34 if c.isdigit(): 35 b=string.atof(b) 36 else : 37 b=b 38 else : 39 b=b 40 value = b 41 d[name]=value 42 print d 43 for eachd in d: 44 l.write(eachd) 45 l.write(" ") 46 l.write("=") 47 eachb=str(d[eachd]) 48 l.write(eachb) 49 l.write("\n") 50 l.close() 51 f.close() 52
原文:http://www.cnblogs.com/heizaiaha/p/3527117.html