视频地址:/video/BV1ap4y1n7DG
try:
import os
(相关资料图)
def helps():
print("""Lesh [] Le 2023-8
help\t显示帮助
run\t运行程序
cd\t切换目录
dir\t查看当前目录下的文件
cmd\t运行控制台命令
set\t建立变量
echo\t输出文本
print\t输出变量
list\t查看所有变量
del\t删除变量
exit\t退出
# 命令参数使用$代替空格""")
def run(file):
('"'+file+'"')
def cd(cd):
try:
if cd == "..":
(('..'))
else:
(() + "\\" + cd)
except FileNotFoundError:
print("找不到目录",cd)
def listdir():
listdir = ()
for i in listdir:
print(i)
def listver(vers):
for i in vers:
print(i + "\t" + vers[i])
vers = {}
helps()
cmds = ["help","run","cd","dir","cmd","set","echo","print","list","del","exit"]
while True:
cmd = input(() + ">").split(" ")
try:
if cmd[0] in cmds:
if cmd[0] == cmds[0]: helps()
elif cmd[0] == cmds[1]: run(cmd[1].replace("$"," "))
elif cmd[0] == cmds[2]: cd(cmd[1].replace("$"," "))
elif cmd[0] == cmds[3]: listdir()
elif cmd[0] == cmds[4]: print((cmd[1].replace("$"," ")).read())
elif cmd[0] == cmds[5]: vers[cmd[1].replace("$"," ")] = cmd[2].replace("$"," ")
elif cmd[0] == cmds[6]: print(cmd[1].replace("$"," "))
elif cmd[0] == cmds[7]: print(vers[cmd[1].replace("$"," ")])
elif cmd[0] == cmds[8]: listver(vers)
elif cmd[0] == cmds[9]: (cmd[1].replace("$"," "),)
elif cmd[0] == cmds[10]: break
else:
print(cmd[0],"不是命令")
except IndexError:
print(cmd[0],"命令需要参数")
except KeyError:
print("没有",cmd[1].replace("$"," "),"变量")
except:
print("发生未知错误")
标签: