马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这几天看的永久存储,应该是对文件的基本操作很实用!P54-P56 ###########################################P54
f=open('./fishc.txt','w')
f.write('I love Python.\n')
f.writelines(['I love Fishc.\n','I love my wife.'])
f.close()
######################################
f=open('./fishc.txt','r+')
print(f.readable())
print(f.writable())
for each in f:
print(each)
print(f.tell())
f.seek(0)
print(f.readline())
print(f.read())
f.write('I love my WIFI')
f.flush()
f.truncate(29)
f.close()
######################################
f=open('./fishc.txt','w')
f.close()
###########################################P55
from pathlib import Path
print(Path.cwd())
p=Path(r'D:\\work\\python\\untitled\\study\\')
q=p /'fishc.txt'
print(p.is_dir())
print(q.is_dir())
print(q.is_file())
print(p.name)
print(q.name)
print(q.stem)
print(q.suffix)
print(p.parent)
print(q.parent)
ps =p.parents
for each in ps:
print(each)
print(p.stat())
print(p.stat().st_size)
print(Path('../FishC.txt').resolve())
print(p.iterdir())
for each in p.iterdir():
print(each)
y=[x for x in p.iterdir() if x.is_file()]
print(y)
n=p/'fishc'
n.mkdir(exist_ok=True)
n=p/'fishc/a/b/c'
n.mkdir(exist_ok=True,parents=True)
n=n/'Fishc.txt'
f=n.open('w')
f.write('I love bitch')
f.close()
# n.rename('./Newfishc.txt')
# m=Path('Newfishc.txt')
# m.replace(n)
# n.unlink()
# n.parent.rmdir()
p=Path('.')
p.glob('*.txt')
list(p.glob('*.txt'))
###########################################P56
f=open(r'D:\work\python\untitled\study\a.txt','w')
f.write('I love FishC')
f.close()
with open('./a.txt','w') as f:
f.write('heihei')
import pickle
x,y,z=1,2,3
s='FishC'
l=['小甲鱼',520,3.14]
d={'one':1,'two':2}
with open('./data.pkl','wb') as f:
pickle.dump(x,f)
pickle.dump(y, f)
pickle.dump(z, f)
pickle.dump(s, f)
pickle.dump(l, f)
pickle.dump(d, f)
with open('./data.pkl','rb') as f:
x=pickle.load(f)
y = pickle.load(f)
z = pickle.load(f)
s = pickle.load(f)
l = pickle.load(f)
d = pickle.load(f)
print(x,y,z,s,l,d,sep='\n')
|