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

你可能感兴趣的:(学习打卡)