简体   繁体   中英

What is the fastest way to convert a folder with 10k .txt files into an array (python)

corpus = []
for i in tqdm(ways):
  f = open(i,'r')
  print(f.read())
  corpus.append(preprocess_text(f.read()))
  f.close()

ways: array of ways to files in the folder

it take to much time (1 hour), can you help me, to make it faster please

corpus = [] 
for i in tqdm(ways):    
    with open(i, 'r') as f:       
        corpus.append(preprocess_text(f.read())) 

This code works faster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM