簡體   English   中英

列表對象沒有屬性拆分

[英]List Object has no Attribute Split

基本上是標題所說的:我正在嘗試創建一個程序來檢測文件中的用戶名和密碼。 但是,每當我運行它時,都會出現此錯誤:

Traceback (most recent call last):
  File "C:/Users/tom11/Desktop/Data Login.py", line 33, in <module>
    content  = raw.split(",")
AttributeError: 'list' object has no attribute 'split'

這是出錯的代碼:

UCheck = ""
PCheck = ""
Username = input("Username: ")
Attempts = 3
while UCheck != "Y":
    lines = True
    f = open('Data.txt', 'r+')
    while lines:
        raw = f.readlines()
        content  = raw.split(",")
        if len(raw) == 0:
            print("That Username does not exist!")
            Username = input("Username: ")
        elif Username == content[0]:
            UCheck == "Y"
            lines = False

這是 .txt 文件中的內容:

TheCloudMiner,Password123
TestUser,TestPass
Testing,Tester
Username,Password

我已經閱讀了其他一些答案,但它們對我沒有幫助。 任何幫助將非常感激。

readlines()返回一個字符串列表,而不是一個字符串。 你想分別在每一行上應用split() ,所以你應該用類似的東西迭代它

for line in open(...).readlines():
    username, password = line.split(",")
    # rest of your code

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM