Read File in Python
来源:互联网 发布:卖毛线比较好的淘宝店 编辑:程序博客网 时间:2024/05/17 07:50
- consider file object as an iterator
with open(...) as f: for line in f: <do something with line>
The with statement handles opening and closing the file, including if an exception is raised in the inner block. The for line in f treats the file object f as an iterable, which automatically uses buffered IO and memory management so you don’t have to worry about large files.
2.the difference between read,readline and readlines
read: read all of the file
readline:read next line
readlines: read all the file in a iterator
123.txt
lalalagwhwhwhwhwh
read
f = open('123.txt','r')a = f.read()a[out]:'lalala\ng\nwhwhwhwhwh'
readline
f = open('123.txt','r')a1 = f.readline()a1[out] lalalaa2 = f.readline()a2[out] ga3 = f.readline()a3[out] whwhwhwhwh
readlines
f = open('123.txt','r')a = f.readlines()a[out] ['lalala','g','whwhwhwhwh']type(a)[out] <type 'list'>
0 0
- Read File in Python
- file operate in python (open write read close )
- python read write file
- python read file
- [python] read file
- read .off file in matlab
- Python file read and wirte
- python read file(f,csv)
- Read Large Files in Python
- read file in kernel (flip_open and flip_close)
- read UTF-8 text file in C++
- Read properties file in a jar
- Read the Last line in a file
- File Management in Python
- write file in python
- file handling in python
- How to read Json file or text file in Spark
- python read xml file--simple example
- uva 11292 勇者斗恶龙
- 嵌入式开发叙述
- 服务器(多GPU)caffe安装和编译
- 【Unity&NGUI】背包系统物品的累加
- Consul 入门笔记
- Read File in Python
- DIGITS安装和配置
- 关于逐项作用函数的用法
- 新手看Mockplus2.3
- markdown改变字体颜色和大小
- LeetCOde231&326详细分析并附求解代码
- AFNetworking3.1.0源码分析(十四)AFHTTPSessionManager
- 多线程,线程池,使用CompletionService通过Future来处理Callable的返回
- xutils的http模块