Python学习第5次打卡

1.window下的路径分隔符和mac上的一样吗
不一样

2.如何查看当前工作目录
import os
os.getcwd()

3.如何切换当前工作目录
import os
os.chdir(‘path’)

4.如何创建新文件夹
import os
os.makedirs(‘C:\delicious\walnut\waffles’)

5.如何将绝对路径修改为相对路径
import os
os.path.relpath(‘C:\Windows’,‘C:\’)

6.如何查看一个路径的目录名称、基本名称
path=‘C:\Windows\System32\calc.exe’
os.path.basename(path)
os.path.dirname(path)

7.如何查看文件夹里面的内容
os.listdir(‘C:\Windows\System32’)

8.如何查看一个文件大小
os.path.getsize(‘C:\Windows\System32\calc.exe’)

9.如何利用open读取、写入文件
helloFile=open(‘C:\Users\mayuanshu\hello.txt’,‘r’) 读取
helloFile=open(‘C:\Users\mayuanshu\hello.txt’,‘a’) 覆写
helloFile=open(‘C:\Users\mayuanshu\hello.txt’,‘w’) 添加

10.利用shelve比一般的写入文件有什么优点?
在程序中,添加“保存”和“打开”功能,也就是能够保存一些设置到一个shelf文件

11.如何利用pprint写入.py后缀的文件
使用pprint.pformat()函数

12.如何复制文文件
import shutil,os
shutil.copy(‘C:\spam.txt’,‘C:\delicioous’)

13.如何移动文件,如何给文件改名字
import shutil
shutil.move(‘C:\bacon.txt’,‘C:\eggs’)

14.如何稳妥的删除文件(先去回收站那种)
import send2trash
import os
helloFile=open(‘hello.txt’,‘a’)
helloFile.close()
send2trash.send2trash(‘hello.txt’)

15.如何压缩文件
import zipfile,os
os.chdir(‘C:\’)
exampleZip=zipfile.ZipFile(‘example.zip’)

16.如何解压文件
import zipfile,os
os.chdir(‘C:\’)
exampleZip=zipfile.ZipFile(‘example.zip’)
exampleZip.extractall()
examleZip.close()

17.项目实践
P149生成AB卷的内容,相当的漂亮!!请打卡完成,要求看到你的实现代码。
P165批量修改名字的内容,相当实用,请打卡完成,同上。
压缩包内容,搞清楚原理即可,实用性不高,不要求完成。
上面问题先欠一下吧,上班了工作压力有点大,端午放假一定补上 T^T

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值