python 檔案讀寫練習
#!/usr/bin/python
#對檔案進行讀寫操作練習,將陳智濤和客服的對話分開,分別存到customer和service檔案>中,並且遇到========,就對檔案加1,重新寫入
def fileSave(filename,content,count):
filename = filename+'_'+str(count)+'.txt'
f = open(filename,'w')
f.writelines(content)
f.close()
def splitFile(filename):
f = open('record.txt')
customer = []
service = []
count = 1
for line in f:
if line[:6] != '======' and line.strip() != '':
(role,record) = line.split(':',1)
if '陳智濤'== role:
customer.append(record)
if '客服' == role:
service.append(record)
else:
fileSave('customer',customer,count)
fileSave('service',service,count)
customer = []
service = []
count +=1
fileSave('customer',customer,count)
fileSave('service',service,count)
f.close()
splitFile('record.txt')
相關文章
- Python之檔案讀寫小練Python
- python學習之讀寫檔案Python
- Python 讀寫檔案Python
- Python——檔案讀寫Python
- 「Python」:檔案讀寫Python
- Python 檔案讀寫(Python IO)Python
- python讀寫excel檔案PythonExcel
- python檔案讀寫操作Python
- 【python系統學習17】python中的檔案讀寫Python
- Python中的檔案讀寫Python
- Python:讀寫檔案(I/O) | 組織檔案Python
- Python檔案讀寫、StringIO和BytesIOPython
- python config配置檔案的讀寫Python
- Python檔案讀寫--錯誤一Python
- Python 簡明教程 --- 24,Python 檔案讀寫Python
- Python中的檔案的讀寫操作Python
- python檔案建立、讀取和寫入Python
- Python中讀寫Parquet檔案的方法Python
- Python讀寫EXCEL檔案常用方法大全PythonExcel
- Python讀寫檔案你真的瞭解嗎?Python
- Python常見檔案讀寫方法有哪些?Python
- python讀寫excel檔案簡單應用PythonExcel
- python檔案無法讀寫怎麼辦Python
- Python中的檔案讀寫-實際操作Python
- Python中檔案的讀寫、寫讀和追加寫讀三種模式的特點Python模式
- (Python基礎教程之十二)Python讀寫CSV檔案Python
- 檔案排版(文字檔案讀寫)
- C++學習筆記----讀寫檔案C++筆記
- Golang 讀、寫檔案Golang
- keras讀寫檔案Keras
- 檔案的讀寫
- Python 3 學習筆記之——鍵盤輸入和讀寫檔案Python筆記
- 學習筆記(30):Python資料清洗實戰-Excel檔案讀寫筆記PythonExcel
- C++讀寫檔案C++
- 普通檔案的讀寫
- C++檔案讀寫C++
- VBA建立文字檔案、讀寫文字檔案
- python檔案操作-讀寫刪除複製總結Python
- python中如何使用scipy.io讀寫.mat檔案?Python