python实例 文件处理
2023-09-11 14:18:16 时间
对比Java,python的文本处理再次让人感动
#! /usr/bin/python
spath="D:/download/baa.txt"
f=open(spath,"w") # Opens file for writing.Creates this file doesn't exist.
f.write("First line 1.\n")
f.writelines("First line 2.")
f.close()
f=open(spath,"r") # Opens file for reading
for line in f:
print("每一行的数据是:%s"%line)
f.close()
知识点:
- open的参数:r表示读,w写数据,在写之前先清空文件内容,a打开并附加内容.
- 打开文件之后记得关闭
相关文章
- Python脚本写端口扫描器(socket,python-nmap)
- Python kafka操作实例(kafka-python)
- Python repr() 函数用法及实例(各种类型转字符串)
- Python @staticmethod实例
- 中途转行python?怎么学?没有基础的我30了自学Python转行靠谱吗?
- python基础——类和实例
- 将自己OpenCV-Python-PyCharm开发环境的Python-3.6.8更换为python-3.9.10的详细过程记录
- python+requests接口自动化测试框架实例详解教程
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 【python】+704个常用工具Python库
- 基于python的密码生成器实例解析
- Python中的join()函数的用法实例分析
- caffe的python接口学习(4):mnist实例---手写数字识别
- 《像计算机科学家一样思考Python(第2版)》——1.3 第一个程序
- 《Python核心编程(第3版)》——2.7 相关模块
- 《Python和Pygame游戏开发指南》——2.3 建立一个Pygame程序
- 【Python学习过程】关于入门Python初期接触到的函数
- 用Python实现邮件发送Hive明细数据
- Python实例 复制文件
- python如何将实例用作属性
- Python 教程之如何使用 matplotlib 在 python 中绘制数学函数
- 【转载】python的魔法方法———A Guide to Python's Magic Methods
- python爬虫入门(六) Scrapy框架之原理介绍
- Python实例---基于页面的后台管理[简单版]
- Python实例---三级菜单的实现[high]
- Python实例---三级菜单的实现[low]
- (17)python消息队列,python RabbitMQ
- python第十五课——全局变量and局部变量
- 如何在python中构造时间戳参数