首页 > 其他 > 详细

学习类1

时间:2014-01-20 19:56:00      阅读:374      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 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     
bubuko.com,布布扣

学习类1

原文:http://www.cnblogs.com/heizaiaha/p/3527117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!