I want to return the filename of the files that has been converted by this function.
from more_itertools import chunked
def file_conversion(input_file, output_file_pattern, chunksize):
with open(input_file) as fin:
reader = csv.DictReader(fin, delimiter=',')
for i, chunk in enumerate(chunked(reader, chunksize)):
with open(output_file_pattern.format(i), 'w', newline='') as fout:
writer = csv.DictWriter(fout, reader.fieldnames, delimiter='|')
writer.writeheader()
writer.writerows(chunk)
print("Successfully converted into", output_file)
script_dir = os.path.dirname(os.path.abspath(__file__))
dest_dir = os.path.join(script_dir, 'temp')
try:
os.makedirs(dest_dir)
except OSError:
pass
path = os.path.join(dest_dir,'out{:03}.csv' )
#this creates file as out000.csv and more out001.csv or out002.csv depending upon the number of lines
file_conversion('in.csv', path, 7000)
base_name = os.path.basename(path)
print(base_name) #returns out{03}.csv
This prints out{03}.csv. But I want the result of the filename that has been converted like out000.csv. Is there any-way to return this? If there are more files, how to return the name of them?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…