Learning Python(7) Files
来源:互联网 发布:天谕捏脸数据玉虚男 编辑:程序博客网 时间:2024/06/05 22:52
write:
f = open('data.txt', 'w')f.write('Hello\n')f.write('world\n')f.close()read:
f = open('data.txt')text = f.read()print(text)print( text.split())#Hello#World#['Hello', 'world']
read in binary
data = open('data.txt', 'rb').read()print(data) #b'Hello\r\nworld\r\n'
Operations
f.close(x) close file f.f.fileno(x) get fileno (fd) for f.f.flush(x) flush file's internal buffer.f.isatty() 1 if file is connected to a tty-like dev, else 0f.read([size]) read at most most bytes from file andreturn as a string object. If omitted,read to EOF.f.readline() read one entire line from filef.readlines() read until EOF with readline() and return listof lines read.f.seek(offset, whence=0) set file's position, like "stdio's fseek()". whence == 0 then use absolute indexingwhence == 1 then offset relative to current poswhence == 2 then offset relative to file endf.tell() return file's current positionf.write(str)Write string to file.f.writelines(list)Write list of strings to file.
- Learning Python(7) Files
- learning Python-Tuple and files
- Machine Learning Week2 files
- Learning python 系列7
- Learning Python(7)--Someting Useful
- Python chapter 7 learning notes
- Learning Python
- Learning Python
- Learning Python
- Learning Python
- python learning
- Learning Python
- Learning Python
- Learning Python
- python learning
- Python learning
- Learning Python
- Python Learning
- MySQL的information_schema
- setValue和setObject的区别
- 通讯异常时不要忽略最简单的网线问题
- Android TextView加下划线
- JQuery显示隐藏层
- Learning Python(7) Files
- Thrift入门及Java实例演示
- EditText自动弹出输入法问题
- virtualbox中fedora17安装增强工具失败 Building the main Guest Additions module [失败]
- The C programming Language -1.10 External Variables and Scope
- 小菜的ArcObjects学习之路------如果通过MapDocument访问地图和图层
- JAVA原创学习(—)
- 首发Zend Studio 9.0.3正式版注册破解
- EditText属性