Last active
March 2, 2020 01:48
-
-
Save rovesoul/dc82048a6db4a9c97423608b1d4e8b8f to your computer and use it in GitHub Desktop.
单词检测用的想法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
""" | |
合并多个txt | |
""" | |
# 获取目标文件夹的路径 | |
path = "xxxx/xxxx/" | |
# 获取当前文件夹中的文件名称列表 | |
filenames = os.listdir(path) | |
result = "文章粘进来.txt" | |
# 打开当前目录下的result.txt文件,如果没有则创建 | |
file = open(result, 'w+', encoding="utf-8") | |
# 向文件中写入字符 | |
# 先遍历文件名 | |
for filename in filenames: | |
print(filename+' ',end='') | |
filepath = path + '/' | |
filepath = filepath + filename | |
# 遍历单个文件,读取行数 | |
try: | |
for line in open(filepath, encoding="utf-8"): | |
file.writelines(line) | |
file.write('\n') | |
print('ok') | |
except:UnicodeDecodeError | |
# 关闭文件 | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment