python:文件管理
2019-04-15 23:19
113 查看
版权声明:https://blog.csdn.net/zjguilai https://blog.csdn.net/zjguilai/article/details/89323366
’’‘read files’’'
with open('pi_digits.txt') as file_object: contents = file_object.read() print(contents) print(contents.rstrip()) for line in file_object: print(line.rstrip() + ".\n")
’’‘must reopen once’’'
with open('pi_digits.txt') as file_object: lines = file_object.readlines() pi_string ='' for line in lines: pi_string +=line.rstrip() print(pi_string) print(len(pi_string)) with open('/users/apple/Desktop/pi_digits.txt') as file_object: contents = file_object.read() print(contents) print(contents.rstrip()) lines = file_object.readlines() for line in lines: print(line.rstrip() + ".\n")
’’‘write files’’'
filename = 'programming.txt' with open(filename, 'w') as file_object: file_object.write("I love programming!") file_object.write("\nI don't means that meaning!") with open(filename, 'a') as file_object: file_object.write("\nwhat do you meaning!\n") file_object.write("I just use it make money!")
实验结果:
================ RESTART: /Users/apple/Documents/FileRead.py ================
3.1415926535
8979323846
2643383279
3.1415926535
8979323846
2643383279
3.141592653589793238462643383279
32
3.1415926535
8979323846
2643383279
3.1415926535
8979323846
2643383279
相关文章推荐
- Python 创建、读取和写入文件以及yield关键字- 千月的python linux 系统管理指南学习笔记(14)
- Python-day3作业-haproxy配置文件管理脚本
- Python学习笔记 8--文件的管理、模块与包
- python文件打包格式,pip包管理
- Python3学习笔记10-标准库之正则、时间、路径、文件管理、存储对象
- Python文件管理对相应目录下的进删除、重命名、移动文件等相应操作
- Python 文件管理实例详解
- Python标准库04 文件管理 (部分os包,shutil包)
- 详解用python实现基本的学生管理系统(文件存储版)(python3)
- Python文件管理对相应目录下的进删除、重命名、移动文件等相应操作
- python项目包和文件的管理以及如何引用相对路径的包和模块
- python文件管理
- python-文件管理
- 谈谈python文件管理中的file、seek、truncate
- python标准库:文件管理(os)
- python学习之文件管理
- Python标准库04 文件管理 (部分os包,shutil包)
- python(基于列表/将学生管理系统写入本地文件)
- python脚本管理日记文件
- python文件管理