python文件操作(創(chuàng)建與讀?。?創(chuàng)新互聯

海豐網站建設公司成都創(chuàng)新互聯公司,海豐網站設計制作,有大型網站制作公司豐富經驗。已為海豐超過千家提供企業(yè)網站建設服務。企業(yè)網站搭建\外貿營銷網站建設要多少錢,請找那個售后服務好的海豐做網站的公司定做!>###############################創(chuàng)建文件########################################### #!/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()

本文標題:python文件操作(創(chuàng)建與讀?。?創(chuàng)新互聯
本文URL:http://www.muchs.cn/article6/dsssig.html

成都網站建設公司_創(chuàng)新互聯,為您提供定制網站品牌網站設計、網站維護、品牌網站制作、網站制作、靜態(tài)網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

網站托管運營