1 回答
TA贡献1785条经验 获得超4个赞
如果我们知道您要如何处理返回的数据会很有帮助,我们可以为您提供更多帮助,但这应该会让您朝着正确的方向前进。
def my_function():
with open(r'features.csv', 'r') as f:
checker = lambda i: bool(i and i.strip())
reader = csv.reader(f)
header = next(reader)
folders = next(
{
header[0]: [row[0]],
'Feature Name': list(filter(checker, row[:1])),
'Child folder': list(filter(checker, row[1:]))
} for row in reader
)
foldersinlist = list(folders.values())
lists = sum(foldersinlist, [])
# print(lists) #Instead of this, let's return the value:
return lists
my_data = my_function() #we're setting my_data to the returned-value of my_function
print (my_data) #Now you can us my_data wherever you need the result of my_function
添加回答
举报