python-打开文件与读写文件
来源:互联网 发布:域名为什么收费 编辑:程序博客网 时间:2024/06/14 02:21
#!/usr/bin/python# encoding: utf8#with 语句不只是针对文件而言的,它是一个用来创建运行时环境的通用框架(genericframework),告诉对象它们正在进入和离开一个运行时环境。print '\u9fa5'print '\u003f'#创建文件并写入内容with open('test.txt',mode='w') as a_file:a_file.write('test successd')print(a_file.mode)print(a_file.name)with open('test.log', mode='w') as b_file:b_file.write('xxxooo=') #读取文件内容with open('t.txt') as c_file:print(c_file.read()) print(c_file.seek(1)) #seek()方法使定位到文件中的特定字节print(c_file.read(10))#参数表示所读字符的个数print(c_file.tell())#在文件后追加内容with open('test.txt',mode='a') as a_file:a_file.write('and xxx ooo successd')with open('test.txt') as d_file:print(d_file.read()) #一次读取一行,并打印出行号和数据print '-----------'line_number = 0with open('t.txt') as e_file:for a_line in e_file:line_number += 1print '{0}{1}'.format(line_number,a_line.rstrip())#二进制文件an_image = open('ttt.png', mode='rb')print (an_image.mode)print(an_image.name)print(an_image.encoding)print(an_image.tell()) # 0data = an_image.read(3) #Nprint (data)print (type(data)) #str ??data = an_image.read()print(len(data))
阅读全文
0 0
- python-打开文件与读写文件
- 文件的打开与读写
- 打开文件 读写文件
- C的文件打开关闭与读写
- python二进制读写文件与普通文件
- python文件读写操作---文件路径含有中文打开错误
- 文件操作-打开、读写
- python--python读写文件
- 第24课 Python文件打开、读写模式详解
- python 中文编码处理与文件读写
- python 文件的读写与查找
- python文件的读写与合并
- python文件读写与编码解码
- Python基础知识之文件读写与修改
- Python读写与追加excel文件
- Python函数打开与文件操作总结
- python 文件的打开与关闭
- 创建,打开,读写文件实例
- 《Python编程入门经典》笔记
- 管道实现ps -aux | grep a.out
- 双向链表
- baidu
- 欢迎使用CSDN-markdown编辑器
- python-打开文件与读写文件
- 母牛的故事(蓝桥杯)
- 《Python网络数据采集》学习中遇到的问题
- Python安装scipy,beautifulsoup,Scrapy
- 动态符号链接的细节
- 2017年上海金马五校程序设计竞赛 Problem C : Count the Number
- 线性回归的概率解释及局部加权回归
- 强大的vim配置文件,让编程更随意
- 你的团队需要一个会讲故事的人-用愿景实现目标