import os
import shutil
os.makedirs("/home/project/test1/first/second/")
shutil.move("/home/project/test1/first/second/", "/home/project/test2/")
os.mknod("/home/project/test2/lanqiao.txt")
exit()
编写一个脚本程序,需要实现对 /home/project/files 目录下的文件类型进行统计。然后根据用户输入,返回对应文件类型的个数。
文件路径为 /home/project/filetype.py。
文件类型不存在时,返回 0。
最终实现的效果如下:
图片描述

import os
file_path = "/home/project/files"
file_type = input("请输入文件类型:")
num = 0
for root, dirs, files in os.walk(file_path):
for f in files:
if f.split(".")[1] == file_type:
num = num + 1
print(num)
本次挑战,我们需要编写脚本实现对蓝桥云课课程页的访问,并对其源码进行保存。
蓝桥云课课程页: https://www.lanqiao.cn/courses/
import os
import requests
r = requests.get("https://www.lanqiao.cn/courses/")
result = r.text
with open(os.getcwd() + "/lanqiao.html", "w") as f:
f.write(result)