try: with open(os.path.join(folder_path, file), 'r', encoding='utf-8') as f: print(file) txt_contents.append(f.read()) except UnicodeDecodeError: with open(os.path.join(folder_path, file), 'r', encoding='ansi') as f: print(file) txt_contents.append(f.read())
11-28
454
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-21
350
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)