Generation

generate functionThu, 23 Mar 2023

Write code that uses import os, import glob or other libraries to write all the text files at this url into one variable book_files book_files = ('http://stup.pro/wp-content/uploads/2023/03/*.txt') book_files

import os def read_files_in_directory(directory): for filename in os.listdir(directory): if not filename.endswith('.txt'): continue with open(filename, 'r') as f: lines = [l.strip() for l in f.readlines()] print(lines) return lines read_files_in_directory(r'C:\Users\USER\Desktop\Python\Python Basics')

Questions about programming?Chat with your personal AI assistant