"""
-*- conding:UTF-8 -*-
/ 我一直在找你
/ 我找到你時
/ 我就等于找到了全世界
DOVE
"""
import os
import os.path
infors = {} # 創(chuàng)建一個儲存內(nèi)容的字典
url_file = open("D:\python\password.txt", "r+") # 打開文件
content = url_file.readlines() # 緩沖文件內(nèi)容到content
url_file.close()
def menu():
"""創(chuàng)建一個菜單函數(shù)"""
print("=" * 30)
name = "密碼本 V1.0"
print(name.center(30))
print("增加 【1】")
print("刪除 【2】")
print("修改 【3】")
print("查找 【4】")
print("退出 【5】")
print("=" * 30)
def add():
"""創(chuàng)建一個添加信息函數(shù)"""
url_file = open("D:\python\password.txt", "r+")
input_add_name = input("請輸入要添加的名稱:")
add_call_find = find(input_add_name)
if add_call_find[0] == 0:
input_add_url= input("請輸入你要添加的URL:")
input_add_explian = input("請輸入URL的說明:")
infors["URL名稱:"] = input_add_name
infors["URL:"] = input_add_url
infors["URL說明:"] = input_add_explian
data = str(infors) + "\n"
url_file.seek(0,2)
url_file.write(data)
url_file.flush()
url_file.close()
else:
print("URL名稱已經(jīng)存在籍铁!")
def pop():
"""創(chuàng)建一個刪除信息函數(shù)"""
input_pop_name = input("請輸入你要刪除的URL名稱:")
pop_call_find = find(input_pop_name)
if pop_call_find[0] == 1:
pop_file = open("D:\python\password.txt", "r")
old_file = pop_file.readlines()
write_file = open("D:\python\password.txt", "w")
for temp in old_file:
pop_content = eval(temp)
if pop_content["URL名稱:"] == input_pop_name:
continue
write_file.writelines(temp)
pop_file.flush()
write_file.flush()
pop_file.close()
write_file.close()
print("文件已刪除!")
else:
print("你要刪除的文件不存在呐籽!")
def amend():
"""創(chuàng)建一個修改函數(shù)"""
input_amend_name = input("請輸入你要修改的URL名稱:")
amend_call_find = find(input_amend_name)
if amend_call_find[0] == 1:
input_amend_newname = input("請輸入新的URL名稱:")
input_amend_newurl = input("請輸入新的URL:")
input_amend_newexplain = input("請輸入新的URL說明:")
new_amend_file = open("D:\python\[備份]password.txt", "a+")
for old_file in content:
old_file = eval(old_file)
if old_file["URL名稱:"] == input_amend_name:
infors["URL名稱:"] = input_amend_newname
infors["URL:"] = input_amend_newurl
infors["URL說明:"] = input_amend_newexplain
new_content = str(infors) + "\n"
new_amend_file.write(new_content)
continue
new_content = str(old_file) + "\n"
new_amend_file.writelines(new_content)
new_amend_file.close()
url_file.close()
file_name = os.path.basename("D:\python\password.txt")
os.chdir("D:\python")
os.remove("D:\python\password.txt")
os.rename("[備份]password.txt",file_name)
else:
print("你要修改的文件不存在!")
def find(x):
"""創(chuàng)建一個查找函數(shù)工具,找到函數(shù)名稱返回1 沒找到返回0"""
#input_find_name = input("請輸入你要查找的URL名稱:")
input_find_name = x
i = 0
for eachline in content:
str_content = eval(eachline)
if str_content["URL名稱:"] == input_find_name:
i = 1
return i , str_content
#else:
#return i , "沒有數(shù)據(jù)"
return i , "沒有數(shù)據(jù)"
def find_true():
"""創(chuàng)建一個查找函數(shù)"""
input_find_true_name = input("請輸入你要查找的URL名稱:")
find_true_call = find(input_find_true_name)
if find_true_call[0] == 1:
print("URL名稱:%s URL: %s URL說明:%s" %(find_true_call[1]["URL名稱:"] , find_true_call[1]["URL:"] ,
find_true_call[1]["URL說明:"]))
else:
print("您查找的函數(shù)不存在奸攻!")
def quit():
print("感謝你的使用羊瘩! -*- ")
def main():
while True:
print("")
menu()
print("")
input_num = int(input("請輸入功能號:"))
if input_num == 1:
add()
elif input_num == 2:
pop()
elif input_num == 3:
amend()
elif input_num == 4:
find_true()
elif input_num == 5:
quit()
break
else:
print("請輸入正確的功能號:")
main()
python_密碼本.py
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門搔谴,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人桩撮,你說我怎么就攤上這事敦第。” “怎么了距境?”我有些...
- 文/不壞的土叔 我叫張陵申尼,是天一觀的道長。 經(jīng)常有香客問我垫桂,道長,這世上最難降的妖魔是什么粟按? 我笑而不...
- 正文 為了忘掉前任诬滩,我火速辦了婚禮,結(jié)果婚禮上灭将,老公的妹妹穿的比我還像新娘疼鸟。我一直安慰自己,他們只是感情好庙曙,可當(dāng)我...
- 文/花漫 我一把揭開白布空镜。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪吴攒。 梳的紋絲不亂的頭發(fā)上张抄,一...
- 文/蒼蘭香墨 我猛地睜開眼安岂,長吁一口氣:“原來是場噩夢啊……” “哼轻猖!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起域那,我...
- 序言:老撾萬榮一對情侶失蹤咙边,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后琉雳,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體样眠,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年翠肘,在試婚紗的時候發(fā)現(xiàn)自己被綠了檐束。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站邮旷,受9級特大地震影響黄选,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜婶肩,卻給世界環(huán)境...
- 文/蒙蒙 一办陷、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧律歼,春花似錦民镜、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽们童。三九已至,卻和暖如春鲸鹦,著一層夾襖步出監(jiān)牢的瞬間慧库,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓嵌戈,卻偏偏與公主長得像覆积,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子熟呛,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 做python項(xiàng)目宽档,需要用到mysql,一般用python-mysql庵朝,安裝時遇到錯誤提示如下: Trace的關(guān)鍵...
- 在linux系統(tǒng)安裝MySQL-Python模塊一直在報這個錯吗冤,Google搜索了很久,看了一些不靠譜的解決方案浪...
- python3登錄極路由并讀取寬帶帳號帳號密碼,fiddler抓包分析過程略...步驟:1九府、登錄路由椎瘟,提取stok...
- url映射### 先構(gòu)造一個url和類的映射元組 在下面構(gòu)造對應(yīng)的類,如 框架內(nèi)部會把映射元組轉(zhuǎn)換為包含多個由ur...