文件读写
来源:互联网 发布:oute66手机导航软件 编辑:程序博客网 时间:2024/06/05 21:17
#文件操作
# 写入
# text = 'this is first line \n this is second line \n this is last line'
# myfile = open('my_file.txt','w')
# myfile.write(text)
# myfile.close()
# 给文件添加内容 'a'=append 以增加内容的形式打开
addText = '\nthis is add text'
myfile = open('my_file.txt','a')
myfile.write(addText)
myfile.close()
#读取文件内容
file = open('my_file.txt','r');
content = file.read();
print(content)
# 写入
# text = 'this is first line \n this is second line \n this is last line'
# myfile = open('my_file.txt','w')
# myfile.write(text)
# myfile.close()
# 给文件添加内容 'a'=append 以增加内容的形式打开
addText = '\nthis is add text'
myfile = open('my_file.txt','a')
myfile.write(addText)
myfile.close()
#读取文件内容
file = open('my_file.txt','r');
content = file.read();
print(content)
#读取文件内容
#file = open('my_file.txt','r');
#content = file.read();
#print(content)
# 足行读取
file = open('my_file.txt','r');
contents = file.readlines()
# 迭代读取的内容
for line in contents:
print(line)
content = file.readline()
print(content,"hql")
0 0
- 文件读写、剪贴板读写
- 读写文件
- 文件读写
- 读写文件
- 读写文件
- 文件读写
- 读写文件
- 读写文件
- 读写文件
- 文件读写
- 文件读写
- 文件读写
- 文件读写
- 读写文件
- 文件读写
- 文件读写
- 文件读写
- 文件读写
- Redis 数据库之有序集合(zset)
- 15:文件操作(C标准库函数)fopen/fclose/fread/fwrite/fseek/fprintf/fscanf
- BZOJ 2865 字符串识别
- Leetcode Find Peak Element 162
- 在sublime侧边栏点击某文件时如何在新标签页打开,而不顶替原来打开的文件
- 文件读写
- Servlet第一篇【介绍Servlet、HTTP协议、WEB目录结构、编写入门Servlet程序、Servlet生命周期】
- 深度学习caffe实战笔记(14)MATLAB实现可视化cifar10数据集
- tips:Java中的switch的选择因子
- 平面设计大神养成记之PS篇——选择菜单栏
- POJ 3984 迷宫问题
- 做硬件的感想
- 问题二十三:C++中debug简单的运行死机问题
- 算法竞赛入门经典第二章