练习一
写一个程序在要保持文件内容的顺序不变的前提下,去除文件中重复的行。
import os
with open('db.txt', 'r', encoding='utf-8') as read_f, \
open('db.txt.swap', 'w', encoding='utf-8') as write_f:
s = set()
for line in read_f:
if line not in s:
s.add(
本文实例讲述了Python3处理文件中每个词的方法。分享给大家供大家参考。具体实现方法如下:
'''''
Created on Dec 21, 2012
处理文件中的每个词
author: liury_lab
'''
import codecs
the_file = codecs.open('d:/text.txt', 'rU', 'UTF-8')
for line in the_file:
for word in line.split():
print(word, end = |