使用os和os.path以及函数的递归完成: 给出一个路径,遍历当前路径所有的文件及文件夹 打印输出所有的文件(遇到文件输出路径,遇到文件夹继续进文件夹)代码
importos.pathaspathimportos file_path_dir="E:\\A云计算\\20251013python\\Code\\09_package\\test_module"deffor_file(path1):forfileinos.listdir(path1):path2=path.join(path1,file)ifpath.isfile(path2):print(f"文件名: ",{path2})elifpath.isdir(path2):for_file(path2)for_file(file_path_dir)使用加密模块及IO模拟登录功能,要求使用文件模拟数据库存储用户名和密码。代码
#数据库存储的是加密后的用户名和密码importhashlib#1 定义函数对传入的字符串进行加密defencryption(str):slat="@@##!!"res=hashlib.md5(str.encode("utf-8"))res.update(slat.encode("utf-8"))returnres.hexdigest()#定义数据库的用户名和密码username_mysql=encryption("zhangsan")password_mysql=encryption("123")print(username_mysql)#模拟登录的过程username=input("username: ")password=input("password: ")deflogin(username,password):returnTrueifencryption(username)==username_mysqlandencryption(password)==password_mysqlelseFalseprint("登录成功"iflogin(username,password)else"登录失败")