The code you want to fill out is as follows.
There are several txt files in the folder, and you print out a list of them first I'd like to print out the contents of each txt file using repetitive statements. It's not combined.
Bringing the list I wrote a code to print out the content I don't know how to do both at once.
Please answer me.
python txt
import os
def show_directory(path):
r = []
path += '/'
files = os.listdir(path)
for file in files:
filename = os.path.join(path, file)
ext = os.path.splitext(filename)[-1]
if ext == '.txt':
r.append(path+file)
return r
def show_file(filelist):
for file in filelist:
with open(file) as f:
print(file)
for i in f:
print(i, end='\n\n')
if __name__ == "__main__":
tmp = show_directory('./ans')
show_file(tmp)
There is no content of the source code, so I think the content of what to do will be limited, and you can refer to the aboveFor Use
© 2025 OneMinuteCode. All rights reserved.