1 Star 0 Fork 152

杜帅/e0401-file-io_1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
convert.py 769 Bytes
一键复制 编辑 原始数据 按行查看 历史
dushuai 提交于 2023-12-03 10:55 . jobs done
import os
# 定义输入文件名、输出文件名、换行符和编码方式
input_file = "unknown.txt"
output_file = "known.txt"
newline = "\r\n"
encoding = "utf-8"
# 打开输入文件并读取文本内容
with open(input_file, "r", encoding="UTF-16BE") as file:
text = file.read()
# 将文本按照指定的换行符分隔成多行
lines = text.split(newline)
# 将多行文本重新拼接成以指定的换行符为换行符的文本
text_newline = newline.join(lines)
# 将文本以指定的编码方式写入到输出文件中
with open(output_file, "w", encoding=encoding, newline=newline) as file:
file.write(text_newline)
# 输出提示信息
print(f"Converted {input_file} to {output_file} using {encoding} encoding and {newline} newline.")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/duushuai/e0401-file-io_1.git
git@gitee.com:duushuai/e0401-file-io_1.git
duushuai
e0401-file-io_1
e0401-file-io_1
master

搜索帮助