Python txt文件的读写
2018-04-02 18:20
423 查看
import codecs
import random
i=0
def write_txt(txt, path):
global i
f = codecs.open(path, 'a+', 'utf8')
if i==200:
i=0
f.write('\r\n')
f.write(str(txt)+" ")
f.close()
i+=1
for j in range(10000):
write_txt(random.randint(1750,2250),"D:\point.txt")
fP=open('D:\point.txt','r');
num=(fP.readline()).split()
for x in num:
print(int(x))
print(num)
for i in range(3000):
print(int(fP.readline())+int(fP.readline())," ")
向一个TXT文件写入随机生成的一行200个的数字。在书写读取中要意识到:写入和读取出来的都是字符串,如果要使用请加上强转。对于读取到的内容来说可以学习一下split()方法,默认不加参数时是分割以(逗号,空格,换行)为标识!
import random
i=0
def write_txt(txt, path):
global i
f = codecs.open(path, 'a+', 'utf8')
if i==200:
i=0
f.write('\r\n')
f.write(str(txt)+" ")
f.close()
i+=1
for j in range(10000):
write_txt(random.randint(1750,2250),"D:\point.txt")
fP=open('D:\point.txt','r');
num=(fP.readline()).split()
for x in num:
print(int(x))
print(num)
for i in range(3000):
print(int(fP.readline())+int(fP.readline())," ")
向一个TXT文件写入随机生成的一行200个的数字。在书写读取中要意识到:写入和读取出来的都是字符串,如果要使用请加上强转。对于读取到的内容来说可以学习一下split()方法,默认不加参数时是分割以(逗号,空格,换行)为标识!
相关文章推荐
- Revit中Dynamo编程——在Python Script中读写txt格式文件
- python 简单的txt文件读写
- python 读写txt文件 json文件
- Python中使用不同编码读写txt文件详解
- Python读写txt文本文件的操作方法全解析
- python笔记 对txt文件的读写
- python 读写txt文件 json文件的实现方法
- python读写不同编码txt文件
- python读写不同编码txt文件
- python读写txt文件
- python读写不同编码txt文件--转自CSDN
- Python读写txt文本文件的操作方法全解析
- Python 读写txt文件
- Python读写txt文本文件的操作方法全解析
- python读写不同编码txt文件
- python读写不同编码txt文件
- 9 python txt文件读写操作
- 基于python的-本地.txt文件的读写
- Python 读写txt文件中文简单处理
- python2.7中编码问题以及txt文件读写的注意事项