我要删除嵌套列表(段落)中的元素,遇到的代码为nil,
import os
import csv
import pandas as pd
main_folder = 'path\\to\\some_folder'
def get_filename(path):
filenames = []
files = [i.path for i in os.scandir(path) if i.is_file()]
for filename in files:
filename = os.path.basename(filename)
filenames.append(filename)
return filenames
files = get_filename(main_folder)
with open('some.csv', 'w', encoding = 'utf8', newline = '') as csv_file:
for _file in files:
file_name = _file
with open(main_folder +'\\'+ _file,'r') as f:
text = f.read()
writer = csv.writer(csv_file)
writer.writerow([file_name, text])
df = pd.read_csv('some.csv')
# ...then whatever...
这里,每当if条件满足时,我必须将段落列表分配到文档列表中。 例如(如果(eq temp nil)满足,我必须将列表段落分配到列表文档中作为列表文档的元素并重置段落列表,以便我可以在下一次迭代中执行相同的操作,有人可以帮帮我吗