1 回答

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超4個(gè)贊
如果我們知道您要如何處理返回的數(shù)據(jù)會(huì)很有幫助,我們可以為您提供更多幫助,但這應(yīng)該會(huì)讓您朝著正確的方向前進(jìn)。
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
添加回答
舉報(bào)