Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
youyu opened this issue Jun 27, 2023 · 2 comments
Open

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

youyu opened this issue Jun 27, 2023 · 2 comments

Comments

@youyu
Copy link

youyu commented Jun 27, 2023

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

@fearlessxjdx
Copy link

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

@weilycoder
Copy link
Contributor

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 格式的文件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants