【发布时间】:2017-11-05 05:22:28
【问题描述】:
这是我尝试过的:
def CreateDict(BDF):
with open('%sdata\\%s.csv' % (mainDir,BDF), mode='r') as infile:
reader = csv.reader(infile)
for row in reader:
key = row[0]
print("%s%s = %s" % (BDF,[key],row[1:]))
CreateDict(FileName)
Print 给了我正确的答案。但是我想把它放在字典里,而不是把它打印出来。我希望该字典具有 FileName 的名称)。
【问题讨论】:
-
FileName = CreateDict(...)?如果您想将它们放入字典而不是打印,那么这样做。另推荐阅读:nedbatchelder.com/text/names.html -
我去看看,谢谢!
-
我认为使用 return 可能会解决它,再次感谢!
-
哦,对不起,我没有解释清楚。 Createdict 位于具有多个文件名的 for 循环中。所以我不能只把“FileName”放在那里,因为有 FileName1 和 FileName2 等等。但我确实想要一个名为 FileName1 的字典等等。
标签: python function csv dictionary arguments