我失去了我以前的帐户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
'和'和'或'不按照您认为的方式工作。他们在任何一方都需要一个布尔表达式。空字典总是评估“错误”,含有内容的字典(不管它们是什么)评估“真”。 –