鱼C论坛

 找回密码
 立即注册
查看: 2851|回复: 1

[学习笔记] 2022-09-27 学习Python-Day14

[复制链接]
发表于 2022-9-27 16:36:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-9-27 20:18:41 | 显示全部楼层
1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-25 22:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表