luogu-dev / cyaron

CYaRon: Yet Another Random Olympic-iNformatics test data generator
GNU Lesser General Public License v3.0
1.35k stars 168 forks source link

输入输出文件指定编码格式为utf-8,怎么设置? #105

Closed youyu closed 17 hours ago

youyu commented 1 year ago

有些题目,输出中含有中文,生成文件,上传到OJ时,会无法显示

fearlessxjdx commented 4 months ago

同问,在windows下,我用 input_writeln 输出UTF8的中文字符串,写入文件的时候会自动换成GBK的,没能找到相关设置。

weilycoder commented 4 days ago

IO 的构造方式有一种是:

IO(open('data.in', 'w+'), open('data.out', 'w+'))

尝试 open 时改成:

open('data.in', 'w+', encoding='utf-8')

encoding 指定了编码格式。

我只测试了生成输入,测试代码如下:

from cyaron.io import *

name = "test.in"
file = open("test.in", "w+", encoding="utf-8")
# test = IO(name, disable_output=True)
test = IO(file, disable_output=True)
test.input_writeln("你好")

可以生成 utf-8 格式的文件。

Mr-Python-in-China commented 17 hours ago

修了 根据pylint的指示 全部默认采用utf-8格式io