我也学Python系列(一)----第一个Python程序

最近项目闲来没啥事情,学学Python话说Python是Google推崇的语言....大家 应该都懂得,而且最新的.Net 4.0是可以动态加载Python脚本的,多语言,多平台,同一个世界同一个梦想.....

 1 '''

 2 Created on 2011-8-26
 3 
 4 @author: Edison
 5 MakeTextFields
 6 '''
 7 import os
 8 
 9 class fileClass:
10     
11     version=0.1
12     filepath="D:\MakeFileText.txt"
13     
14     def __init__(self):
15         True
16         
17     def MakeFields(self):
18         ls=os.linesep
19         while True:
20             if os.path.exists(self.filepath):
21                 print 'Error %s already exists'%self.filepath
22                 break
23             else:
24                 break
25     
26         print 'Entry Words :'
27         all=[]
28         while True:
29             entrys=input('')
30             if entrys=='Exit':
31                 break
32             else:
33                 all.append(entrys)
34     
35         fobj=open(self.filepath,'w')
36         fobj.writelines(['%s%s'%(x,ls) for x in all])
37         fobj.close()
38         print "Finsihed!"
39         input()
40         
41     def ReadFromText(self):
42         try:
43             fobj=open(self.filepath,'r')
44         except IOError,e:
45             print '*** open file error',e
46         else:
47             for eachline in fobj:
48                 print eachline
49             fobj.close() 
50         
51 if __name__=='__main__':
52     x=fileClass()
53     #x.MakeFields()

54     x.ReadFromText() 

 以上这段代码是可以正常执行的主要应用是用来,读取一段文字和写入一段文字如文件系统的,各位可以自己Debug一下,通过这个也学写一下如何使用Eclipse进行调试.

posted @ 2011-08-26 16:12  tf.li  阅读(116)  评论(0)    收藏  举报