调用createdict时,需要将返回值赋给变量usrdict。试试这个:
import csv
def CreateDict(filename):
UsrDict = {}
with open(filename) as csvfile:
readCSV = csv.reader(csvfile, delimiter=':')
for row in readCSV:
UsrDict[row[0]]=row[1]
return UsrDict
def CreateHumanUsrNameDict(UsrDict):
HumanUsrDict={}
for k, v in HumanUsrDict.items():
if v == len(4):
HumanUsrDict[k:v]
print(HumanUsrDict)
if __name__=='__main__':
UsrDict = CreateDict('Book1.csv')
CreateHumanUsrNameDict(UsrDict)