1、读文件
读文本文件
input = open('data', 'r')
#第二个参数默认为r
input = open('data')
读二进制文件
input = open('data', 'rb')
读取所有内容
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally:
file_object.close( )
读固定字节
file_object = open('abinfile', 'rb')
try:
while True:
chunk = file_object.read(100)
if not chunk:
break
do_something_with(chunk)
finally:
file_object.close( )
读每行
list_of_all_the_lines = file_object.readlines( )
如果文件是文本文件,还可以直接遍历文件对象获取每行:
for line in file_object:
process line
2、写文件
写文本文件
output = open('data', 'w')
写二进制文件
output = open('data', 'wb')
追加写文件
output = open('data', 'w+')
写数据
file_object = open('thefile.txt', 'w')
file_object.write(all_the_text)
file_object.close( )
写入多行
file_object.writelines(list_of_text_strings)
注意,调用writelines写入多行在性能上会比使用write一次性写入要高。
分享到:
相关推荐
com.excelliance.open.LBApplication.apk
主要介绍了adodb.recordset.open(rs.open)方法参数详解,需要的朋友可以参考下
windows.open这个是JavaScript函数,但是在应用起来的时候总会遇到比较多的麻烦,因为参数非常多,用法也非常的多
主要讲解了如何利用window.open打开新窗口,和打开新窗口时的一些参数的设置,很实用的。
layui layer.open()中的select,radio不显示.zip
扩展window.open方法,使得window.open时针对相同的URL地址非打开新窗口,而是仅仅激活已存在窗口,另外,此激活不会刷新页面,不会丢失页面上已存在的数据
访问带https请求忽略ssl证书,避免url.openStream报错javax.net.ssl.SSLHandshakeException url = new URL(imageUrl);...DataInputStream dataInputStream = new DataInputStream(url.openStream());
弹出窗口,并且弹出窗口要求最大化处理,window.open打开的窗口获取到焦点
Web开发中的window.open父子窗口传值问题 部署在tomcat中进行
TOP。layer案例
关于window.open()的详细介绍使用,浏览器对于bom的不同兼容问题
org.simalliance.openmobileapi.jar
关于window.open的一些特性,一些你经常不注意的,值的一看啊
window.open打开新窗口,不被拦截的方法
一、window.open()支持环境: 二、基本语法: 三、示例: 四、各项参数
window.open()参数大全,window.open()参数大全,window.open()参数大全。
弹出窗口,并且弹出窗口要求最大化处理,window.open打开的窗口获取到焦点
window.open()对于各浏览器兼容情况
window.open参数详解.txt
NULL 博文链接:https://shawnfree.iteye.com/blog/598885