我失去了我以前的帳戶ID,所以我開始新的。python太多的值來解壓錯誤和空白輸出
templist=[]
temps1=[]
templist2=[]
tempstat1={}
station1={}
station2={}
import os.path
def main():
#file name=animallog.txt
endofprogram=False
try:
filename=input("Enter name of input file >")
file=open(filename,"r")
except IOError:
print("File does not exist")
endofprogram=True
count=0
count2=0
for line in file:
line=line.strip('\n')
if (len(line)!=0)and line[0]!='#':
(x,y,z)=line.split(':')
templist.append((x,y,z))
record=(x,z)
temps1.append(record)
for x,y in record:
if x in station1 or station2:
if y=='s1':
station1[x]=station1[x]+1
elif y=='s2':
station2[x]=station2[x]+1
elif x not in station1 and station2:
if y=='s1':
station1[x]=1
elif y=='s2':
station2[x]=1
main()
無論如何,夥計們。我寫了這個程序。它基本上是讀有像這個 - > 信息文件(動物:日期:站號)
a01:01-24-2011:s1
a03:01-24-2011:s2
a03:09-24-2011:s1
我想算哪一種動物去哪個站多少次。我不想從各位專家的答案,但只需要知道這個錯誤指─
File "/Applications/Wing101.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 58, in <module>
File "/Applications/Wing101.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 39, in main
builtins.ValueError: too many values to unpack (expected 2)
謝謝:)
EDIT--
改變for x,y in record:
TOfor x in record:
但它打印{}
當我嘗試打印station1
和station2
爲什麼打印空白字典爲station1
和station2
?
你的問題到底是什麼? – jdotjdot
'和'和'或'不按照您認爲的方式工作。他們在任何一方都需要一個布爾表達式。空字典總是評估「錯誤」,含有內容的字典(不管它們是什麼)評估「真」。 –