1、with写文件

save_file = "1.txt"
str_data = "123a\nbc"
with open(save_file, 'a', encoding="utf-8") as f:
f.write(str_data)

  

2、with读文件

# 待读取文件
read_file = "1.txt"
with open(read_file, 'r', encoding="utf-8") as f:
# 1、read():读取文件全部内容
str_data = f.read()
print(str_data) # # 2、readline():逐行读取5行内容
# for i in range(1,5):
# # 读取文件一行内容
# str_data = f.readline()
# print(str_data) # # 3、readlines():按行读取文件内容到列表
# str_list = f.readlines()
# print(str_list) pass

  

with读、写文件的更多相关文章

  1. java读/写文件

    读取文件参考:https://blog.csdn.net/weixin_42129373/article/details/82154471 写入文件参考:https://blog.csdn.net/B ...

  2. C++ 二进制文件 读 写文件

    1 #include <iostream> 2 #include <string> 3 #include<fstream> 4 using namespace st ...

  3. read(),write() 读/写文件

    read read()是一个系统调用函数.用来从一个文件中,读取指定长度的数据到 buf 中. 使用read()时需要包含的头文件: <unistd.h> 函数原型: ssize_t re ...

  4. 关于使用 Java 分片读\写文件

    分片读取文件方法: /** * 分片读取文件块 * * @param path 文件路径 * @param position 角标 * @param blockSize 文件块大小 * @return ...

  5. c# 读/写文件(各种格式)

    最简单的: --------写 //content是要写入文本的字符串 //(@txtPath + @"\" + rid + ".txt");要被写入的TXT ...

  6. RandomAcessFile、MappedByteBuffer和缓冲读/写文件

    项目需要进行大文件的读写,调查测试的结果使我决定使用MappedByteBuffer及相关类进行文件的操作,效果不是一般的高. 网上参考资源很多,如下两篇非常不错: 1.花1K内存实现高效I/O的Ra ...

  7. Pandas 基础(4) - 读/写 Excel 和 CSV 文件

    这一节将分别介绍读/写 Excel 和 CSV 文件的各种方式: - 读入 CSV 文件 首先是准备一个 csv 文件, 这里我用的是 stock_data.csv, 文件我已上传, 大家可以直接下载 ...

  8. 【练习】Java中的读文件,文件的创建,写文件

    前言 大家好,给大家带来Java中的读文件,文件的创建,写文件的概述,希望你们喜欢 读文件 public static void read(String path,String filename){ ...

  9. py库: xlwt 、xlrd (写读EXCEL文件)

    写EXCEL文件 # -*- coding: utf-8 -*- import xlwt book = xlwt.Workbook(encoding = "utf-8", styl ...

  10. Python: 读文件,写文件

    读写文件是最常见的IO操作.Python内置了读写文件的函数. 读写文件前,我们先了解一下,在磁盘上读写文件的功能都是有操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘,所以,读写文件就是请求 ...

随机推荐

  1. oracle 19c jdbc之Reactive Streams Ingestion (RSI) Library

    19c jdbc新特性 https://blogs.oracle.com/dev2dev/whats-new-in-193-and-183-jdbc-and-ucp jdbc实现直接路径加载 http ...

  2. AudioManager: android插上耳机仍然使用扬声器播放音频

    手机音频的输出有外放(Speaker).听筒(Telephone Receiver).有线耳机(WiredHeadset).蓝牙音箱(Bluetooth A2DP)等输出设备.在平时,电话免提.插拔耳 ...

  3. css3逐帧动画

    写css3动画的时候,我们经常用到animation来实现,默认情况下,animation是属于连贯性的ease动画.我们熟悉的animation动画有ease.ease-in.ease-out.li ...

  4. [LeetCode] 273. Integer to English Words 整数转为英文单词

    Convert a non-negative integer to its english words representation. Given input is guaranteed to be ...

  5. [LeetCode] 290. Word Pattern 单词模式

    Given a pattern and a string str, find if str follows the same pattern. Here follow means a full mat ...

  6. 【视频开发】【CUDA开发】FFMPEG硬件加速-nvidia方案

    1.目标 <1>显卡性能参数: <2>方案可行性: 2.平台信息 2.1.查看当前显卡信息 命令:  lspci |grep VGA  信息:  01:00.0 VGA com ...

  7. PKUWC2020自闭记

    我才听说PKU今年对我省高二要求CSP分数>450? 我似乎丧失了一个溜去隔壁的机会? 机会是不存在的qwq THUWC3个数据结构直接送人升天 Day1 T1:感觉相邻的k!个排列是同构的可以 ...

  8. docker下安装nginx并实现https访问

    一.启动容器 docker run --detach --name wx-nginx -p 443:443 -p 80:80 -v /home/nginx/data:/usr/share/nginx/ ...

  9. 什么是REST 、RESTful 、RESTful API?

    介绍 自从Roy Fielding博士在2000年他的博士论文中提出Rest(Representational State Transfer)风格的软件架构模式后,REST就基本上迅速取代了复杂而笨重 ...

  10. mybatis内置参数及foreach使用