第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從文本文件中檢索信息

從文本文件中檢索信息

慕桂英546537 2024-01-16 10:37:55
我想接受用戶輸入的變量“name”,然后我想將account.zk(這是一個普通的文本文件)加載到一個列表中,然后我想檢查輸入是否已經(jīng)在此列表中。如果沒有,我想添加它,相反,我想跳過并繼續(xù)。我自己編寫了這個函數(shù),但沒有成功!有人能理解為什么嗎?# Start Downloading Systemname = input(Fore.WHITE+"Enter Profile Name To Download: ")# Save Account (used for check the updates!)file_object = open("account.zk", "r")for line in file_object:  stripped_line = line.strip()  line_list = stripped_line.split()  list_of_lists.append(line_list)if (len(list_of_lists) != len(set(name))):    print("\n\nAlready in List!\n\n")    file_object.close    time.sleep(5)else:    file_object.close    file_object = open("account.zk", "w")    file_object.write(name + "\n")    file_object.close
查看完整描述

1 回答

?
猛跑小豬

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個贊

我認(rèn)為你想做的是以下幾點(diǎn):


# Start Downloading System

name = input(Fore.WHITE + "Enter Profile Name To Download: ")


# Save Account (used for check the updates!)

file_object = open("account.zk", "r")


list_of_lists = []

for line in file_object:

  stripped_line = line.strip()

  line_list = stripped_line.split()

  list_of_lists.extend(line_list)  # add the elements of the line to the list


if name in list_of_lists:  # check if the name is already in the file

    print("\n\nAlready in List!\n\n")

    file_object.close()

    time.sleep(5)

else:  # if not, add it

    file_object.close()

    file_object = open("account.zk", "w")

    file_object.write(name + "\n")

    file_object.close()


查看完整回答
反對 回復(fù) 2024-01-16
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號