###############################创建文件########################################### #!/usr/bin/env python '''make a test file''' import os ls = os.linesep #get file name fname = raw_input('Enter Filename: ') while True: if os.path.exists(fname): print('ERROR: %s already exists' % fname ) exit() break else: break #get file content(test) lines all = [] print("Enter lines ('.' by itself to quit)") #loop until user terminates input while True: entry = raw_input('> ') if entry == '.': break else: all.append(entry) #write lines to file with proper line-ending with open(fname,'w') as f: f.writelines(['%s%s' %(x,ls) for x in all]) print 'DONE!' ###################################读取文件###################################### #!/usr/bin/env python '''read and display text file''' #get file name fname = raw_input("Enter filename: ") print #attempt to open file for reading try: fobj = open(fname,'r') except IOError,e: print('***file open error:',e) else: #display content to the screen for eachLine in fobj: print eachLine fobj.close()
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款