Linux下Python 文件替换脚本 import sys,os if len(sys.argv)<=4: old_text,new_text = sys.argv[1],sys.argv[2] file_name = sys.argv[3] f = open(file_name,"rb") new_file = open(".%s.bak" % file_name,"wb") for line in f.xreadlines(): pr
''' 吃的文件内容: 过油肉菜 尖椒菜 娃娃菜 ''' import os with open("吃的", mode="r", encoding="utf-8") as f1, \ open("吃的_副本", mode="w", encoding="utf-8") as f2: # s = f1.read() # ss = s.replace("肉", "
import os, time import sys import re def read_old_part(filename, start, end): content = [] recording = False with open(filename) as f: for line in f: line = line.strip() if line == end: break if recording: content.append(line) if line == start: recor
# 读取数据的函数 def readData(filename): with open(filename, 'r') as f: data = f.read().lower() data = list(data.split()) return data words = readData('deng.txt') print (words) print ('File size is {}'.format(len(words)))