def readVenueList(textFile):
venuelist = []
venue = open ("venue.txt","r")
for x in venue :
x = x.split(",")
Name = "Name":(x[0])
Max = "Max": int(x[1])
Cost = "Cost": int(x[2])
venuedict = {Name,Max,Cost}
venuelist.append(venuedict)
venue.close()
return venuelist
答案 0 :(得分:3)
当您编写Name = "Name" : (x[0])
时,它没有定义字典,它会给您一个语法错误。你可以使用
venuedict = {"Name" : x[0], "Max" : int(x[1]), "Cost" : int(x[2])}
代替。
答案 1 :(得分:0)
你的问题很不清楚,不过试试这个:
def readVenueList(textFile):
venuelist = []
venue = open ("venue.txt","r")
for x in venue :
x = x.split(",")
Name = "Name : %s" % (x[0])
Max = "Max : %s" % int(x[1])
Cost = "Cost : %s" % int(x[2])
venuedict = {Name,Max,Cost}
venuelist.append(venuedict)
venue.close()
return venuelist
无论如何你还想做什么:
Name = 'name': (x[0])