def reademail():
f = open("Y11email.csv", "r")
line= "email"+ ","+"fname"+","+"sname"+"password"+"\n"
for line in f:
email,fname,sname,password=line.split(", ")#splits each line however creates an extra space between the lines because of enter
password=password.strip()#strip removes the extra space between the lines
print(email,fname,sname,password)
f.close()
我是新來的python,所以我不明白我不斷收到的錯誤。我希望有人能解釋。如果您需要任何詳細信息,我會在編輯沒有足夠的值來解壓(預計4,得到1)的功能,python
email,fname,sname,password=line.split(", ")#splits each line however creates an extra space between the lines because of enter
ValueError: not enough values to unpack (expected 4, got 1)
我希望它打印這樣的:
[email protected] Name Surname fakepassword
[email protected] Z Y fakepassword
[email protected] Ray Check hello
編輯:我試圖在逗號後移除之間的空間,並試圖到.split( 「\ n」),但有
email,fname,sname,password=line.split("\n")#splits each line however creates an extra space between the lines because of enter
ValueError: not enough values to unpack (expected 4, got 2)
至少我得到了一個更大的價值XD
這是因爲您的文件行沒有任何逗號btw您應該使用'csv'模塊讀取csv文件 –
或者有逗號...只是沒有逗號後跟空格... :) –
是的。 csv模塊_forever_ –