用Python写一个任务管理器进行工作协调
介绍
现在有很多工作管理的系统,我们此次使用Python来自己构建一个简单的任务管理器。
一、添加任务
我们使用一个列表来存储任务,然后添加任务就是append
def add(li, w):
"""
add
:param li: li
:param w: w
:return: none
"""
li.append({f"{len(li) + 1}.": [w, 0, None]})
return
二、删除任务
我们在添加任务的时候是有一些标记,添加进去的标记为0,删除了的标记为-1, 完成了的标记为1.
所以删除就是进行修改标记为-1
def add(li, w):
"""
add
:param li: li
:param w: w
:return: none
"""
li.append({f"{len(li) + 1}.": [w, 0, None]})
return
三、标记任务完成
同上所述,标记人物完成就是进行修改标记为1:
import time
def mark(li, w):
"""
mark
:param li: li
:param w: w
:return: none
"""
li[int(w) - 1][w + "."][1] = 1
# attention to - 1
# finish
li[int(w) - 1][w + "."][2] = f"{time.localtime().tm_hour}:{time.localtime().tm_min}"
return
这里我们还加入了时间作为完成任务的一个记录。
四、查看所有的任务
这个很简单了啦:
def show(li):
"""
show the work
:param li: li
:return: none
"""
# print(li)
for i in li:
print(i)
return
五、退出系统
这个我们没有重新写函数,所以直接在主程序中直接写入怎么退出了。
六、主程序
import sys
import time
from operation import add
from operation import delete
from operation import show
from operation import mark
"""
work program
"""
work_list = []
while True:
print("""Operation:
1.add->a
2.del->d
3.show->s
4.mark->m
5.exit->e""")
operation = input("input operation:")
if operation == "a":
work = input("input work:")
# add
add.add(li=work_list, w=work)
elif operation == "d":
work = input("input work number:")
# delete
delete.delete(li=work_list, w=work)
elif operation == "s":
# show
show.show(li=work_list)
elif operation == "m":
# mark
work = input("input work number:")
mark.mark(li=work_list, w=work)
elif operation == "e":
time_file = \
f"{time.localtime().tm_year}," \
f"{time.localtime().tm_mon}," \
f"{time.localtime().tm_mday}"
with open(time_file + ".txt", "w+") as f:
f.write(f"{time.localtime().tm_year}/"
f"{time.localtime().tm_mon}/"
f"{time.localtime().tm_mday}")
f.write("\n")
for data in work_list:
f.write(f"{data}")
f.write("\n")
continue
f.write("\n")
f.write("by hu yu xuan")
f.close()
sys.exit("bye, bye!")
else:
print("please input again")
到此为止,我们就实现了这个任务管理器的所哟操作。
七、代码汇总
add
def add(li, w):
"""
add
:param li: li
:param w: w
:return: none
"""
li.append({f"{len(li) + 1}.": [w, 0, None]})
return
delete
def delete(li, w):
"""
delete
:param li: li
:param w: w
:return: none
"""
# li.pop(li[int(w) - 1])
li[int(w) - 1][w + "."][1] = - 1
return
mark
import time
def mark(li, w):
"""
mark
:param li: li
:param w: w
:return: none
"""
li[int(w) - 1][w + "."][1] = 1
# attention to - 1
# finish
li[int(w) - 1][w + "."][2] = f"{time.localtime().tm_hour}:{time.localtime().tm_min}"
return
show
def show(li):
"""
show the work
:param li: li
:return: none
"""
# print(li)
for i in li:
print(i)
return
主程序
import sys
import time
from operation import add
from operation import delete
from operation import show
from operation import mark
"""
work program
"""
work_list = []
while True:
print("""Operation:
1.add->a
2.del->d
3.show->s
4.mark->m
5.exit->e""")
operation = input("input operation:")
if operation == "a":
work = input("input work:")
# add
add.add(li=work_list, w=work)
elif operation == "d":
work = input("input work number:")
# delete
delete.delete(li=work_list, w=work)
elif operation == "s":
# show
show.show(li=work_list)
elif operation == "m":
# mark
work = input("input work number:")
mark.mark(li=work_list, w=work)
elif operation == "e":
time_file = \
f"{time.localtime().tm_year}," \
f"{time.localtime().tm_mon}," \
f"{time.localtime().tm_mday}"
with open(time_file + ".txt", "w+") as f:
f.write(f"{time.localtime().tm_year}/"
f"{time.localtime().tm_mon}/"
f"{time.localtime().tm_mday}")
f.write("\n")
for data in work_list:
f.write(f"{data}")
f.write("\n")
continue
f.write("\n")
f.write("by hu yu xuan")
f.close()
sys.exit("bye, bye!")
else:
print("please input again")