def readlines_in_file(file_path): FYLog.fy_log(file_path) if not os.path.exists(file_path): print file_path print '返回false' return False input = open(file_path) lines = input.readlines() input.close() print lines return lines
def replace_line_in_file(file_path, search_key, replace_line_data): filelines = readlines_in_file(file_path) print type(filelines) if not isinstance(filelines, list): FYLog.fy_log("获得文件行内容失败") return False output = open(file_path, 'w') for line in filelines: print "jj" if not line: break if search_key in line: FYLog.fy_log(search_key + 'start') output.write(replace_line_data) else: output.write(line) output.close() FYLog.fy_log("helloworld--start")
def replace_line_in_file(file_path, search_key, replace_line_data): filelines = readlines_in_file(file_path) print type(filelines) if not isinstance(filelines, list): FYLog.fy_log("获得文件行内容失败") return False output = open(file_path,'w'); for line in filelines: print "jj" if not line: break if search_key in line: FYLog.fy_log(search_key + 'start') output.write(replace_line_data) else: output.write(line) output.close() FYLog.fy_log("helloworld--start")