-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Windows下render可以指定CRLF为LF么? #2325
Comments
|
双系统用户,生成的文件需要保存,mac下生成的文件是LF,windows下生成的是CRLF,内容没改动,但是git就不一样了。一般的写文件,输出前可以自己把output处理一遍再输出,但pyecharts的render是封装了。所以没法自己前置操作,要改成LF还要去生成后遍历已经生成的文件改。pandas/jinja会留个配置或者参数让用户自己改一下。 |
|
是的我git用的是统一的,jinja它是这样的 template = env.get_template(template_name)
output = template.render(data=data) jinja的env里面它不管LF还是CRLF,它只能控制utf8(这个也影响双平台,windows下默认不是utf8),但是它的output写入文件的时候,我用pathlib的Path |
|
有了参数才能保证输出一种,自己在代码里指定是\n还是\r\n。现在不处理,同样的代码在mac和windows下运行,会render出不同的文件,是两种。这也是为什么pandas和python官方的write_text都会留一个参数的原因。 |
具体来说,因为pyecharts已经是python3.6+了,所以把engine.py里的这段 def write_utf8_html_file(file_name: str, html_content: str):
with open(file_name, "w+", encoding="utf-8") as html_file:
html_file.write(html_content) 改成 from pathlib import Path
def write_utf8_html_file(file_name: str, html_content: str, newline: str | None = None):
Path(file_name).write_text(html_content, encoding="utf-8", newline=newline) 然后把newline向上一层层都留出来就可以。用户不填,保持现在的默认行为,mac/windows不同行尾。用户填了,就指定。 |
|
那就算了,为了这个极小众需求特地再去用复杂方式处理不值得,等哪天只支持3.10+再解决就行了。 |
|
|
问题
Windows下render默认是CRLF,没有找到设置newline="\n"的地方
运行环境(系统环境及 pyecharts 版本)
Windows 11 / pyecharts 2.0.5
代码及截图
The text was updated successfully, but these errors were encountered: