python文件学习
来源:互联网 发布:历年固定资产投资数据 编辑:程序博客网 时间:2024/04/28 10:58
all=open("w.txt").read()all_n=open("w.txt",'rb').read()print allprint all_nfile_object=open('w.txt')list_of_all_the_lines=file_object.readlines()print list_of_all_the_linesfile_object=open('w.txt')try: all_the_text=file_object.read()finally: file_object.close() print all_the_text
结果:
oh my god! what happen?so funny!oh my god! what happen?so funny!['oh my god! what happen?so funny!']oh my god! what happen?so funny!
当文件中包含换行的时候file_object=open('w.txt')list_of_all_the_lines=file_object.readlines()file_object=open('w.txt')list_of_all_the_lines1=file_object.read().split('\n')file_object=open('w.txt')list_of_all_the_lines2=[L.rstrip('\n') for L in file_object]print list_of_all_the_linesprint list_of_all_the_lines1print list_of_all_the_lines2
['oh my god! \n', 'what happen?\xa1\xa2\n', 'so funny!']['oh my god! ', 'what happen?\xa1\xa2', 'so funny!']['oh my god! ', 'what happen?\xa1\xa2', 'so funny!']
- Python学习 文件遍历
- PYTHON-文件输入输出学习
- 学习PYTHON 之 文件
- python学习文件
- python文件学习
- python学习-文件操作
- Python学习:读文件
- Python学习-文件操作
- Python学习之文件
- python 文件2学习
- python学习 文件IO
- PYTHON文件学习
- python学习:zip文件
- Python的学习&文件
- python学习之 文件
- python学习--文件操作
- python学习——python文件
- python文件查找字符串,python递归学习
- 水稻基因命名
- 【骏河】BDC锁定问题及解决方案
- 155b_Combination
- Linux 分辨率
- NYTimes Objective-C 编程风格指南
- python文件学习
- ACE中的Proactor介绍和应用实例
- WebRTC现状及实现概要
- 黎活明老师黑马android学习总结 Activity生命周期
- Android APK反编译详解(附图)
- android解析json
- 转:javascript 中 new 的作用
- 使用Rational PureCoverage测试代码覆盖率
- Android中自定义可以下拉刷新的ListView(附demo)