题目
1.批量修改文件名
import os
folderName = os.path.realpath('doc')
dirList = os.listdir(folderName)
for name in dirList:
newName = '[西部开源]-' + name
print("重命名 【%s】为【%s】成功! " % (name, newName))
os.rename(folderName + '\\' + name, folderName + '\\' + newName)
2.读取一个文件,显示除了以井号(#)开头的行以外的所有行。
readLineList = []
with open('test.txt') as f:
while True:
readLine = f.readline()
if readLine:
readLineList.append(readLine)
else:
break
for i in readLineList:
if not i.startswith("#"):
print(i)
文件内容:
运行结果:
3.制作一个"密码薄",其可以存储一个网址(例如 www.csdn.net),和一个密码(例如 123456),请编写程序完成这个“密码薄”的增删改查功能,并且实现文件存储功能
"""
运行前test.txt必须不存在或内容为json编码过的 “一个” python字典
主界面输入0,查看所有数据
"""
import json
import os
dbDate = {}
def mainMenu():
print('欢迎使用密码薄&#