file1=open('pima-indians-diabetes.txt','r')
file2=open('out.txt','w+')
#data=file1.read()
i=0
while True:
line=file1.readline()
tt='"'+line[:-1:1]+'"'+','
if i<3:
print(tt)
i+=1
file2.write(tt+'\n')
if not line:
break
file1.close()
file2.close()
#read() 将文本文件所有行读到一个字符串中
#readline() 一行一行的读
#readlines() 将文本文件中所有行读到一个List中,文本文件每一行是list的一个元素
file3=open('out1.txt','w')
for i in open('pima-indians-diabetes.txt','r'): # 文件迭代器
file3.write(i)
file3.close()
print("----------------------------")
t=0
file4=open('out2.txt','w')
with open('pima-indians-diabetes.txt','r') as f:
for i in f:
file4.write('"'+i[:-1:1]+'"'+'\n')
if t<4:
print(i)
t+=1
file4.close()
print("----------------------------")
t=0
file4=open('out3.txt','w')
with open('pima-indians-diabetes.txt','rb') as f:
for i in f:
file4.write(i.decode())
if t<4:
print(i)
t+=1
file4.close()
f=open('007.jpg','rb') # 二进制读取图片
print(f.read())
import os
print(os.name)
print(os.path.abspath('.'))
paths=os.path.abspath('.')+'\hello'
#os.mkdir(paths) # 创建文件夹
#os.rmdir(paths) # 删除文件夹
print(dir(os.path.abspath('.')))
tt=list(x for x in os.listdir('.') if os.path.isdir(x)) #列出当前目录下的所有目录
print(tt)
# 列出.py文件
ttt=list(x for x in os.listdir('.') if os.path.isfile(x) and os.path.splitext(x)[1]=='.py')
print(ttt)
pp='E:/python/test/Class4.py'
tt=os.path.split(pp)
print(tt)
t1=os.path.splitext(pp)
print(t1)