I have built a function to create a dictionary and return it. This function is called get_values, and is structured as follows:
def initiate_values(directory):
for file in glob.glob(os.path.join(directory, '*.[xX][lL][sS]')):
title = os.path.basename(file).lower()
if title == 'etc.xls':
wb = xlrd.open_workbook(file)
wb = wb.sheet_by_name(u'Sheet1')
get_values(file, wb)
def get_values():
info_from_etc = dict()
# build dict
return info_from_etc
It works, in that it creates the dictionary and then when I try and print it, it prints the correct values. However, when I try and call this get_values function from another function, the dictionary returns as “None”. This is my function to call get_values –
def packager():
info_from_etc = initiate_values()
print info_from_etc # this prints "None"
What am I doing incorrectly here, and how would I return the proper dictionary here — that is, a dictionary that is not None.
You need to
returnthe dictionary frominitiate_values: