with open("C:scripts/CUAppVersion.js", 'a') as file:
file.write("if [CUID] = -1 then"
"function GetCUID() { return 0; }"
"else"
"function GetCUID() { return [CUID] });")
这是我的代码,它成功地将JS放入JS文件中,但它将它放在一行而不是我在上面键入它。我知道我的JS代码不完全正确我需要修复它。
如何将该代码放入具有正确布局的JS文件中?
答案 0 :(得分:2)
使用多线字符串。
with open("C:/scripts/CUAppVersion.js", 'a') as file:
file.write("""
if [CUID] = -1 then
function GetCUID() { return 0; }
else
function GetCUID() { return [CUID] });
""".strip())
答案 1 :(得分:0)
将\n
添加到每一行的末尾。
with open("C:scripts/CUAppVersion.js", 'a') as file:
file.write("if [CUID] = -1 then\n"
"function GetCUID() { return 0; }\n"
"else\n"
"function GetCUID() { return [CUID] });\n")
答案 2 :(得分:0)
如何添加一些结束标题\n
?
with open("C:scripts/CUAppVersion.js", 'a') as file:
file.write("if [CUID] = -1 then\n"
"function GetCUID() { return 0; }\n"
"else\n"
"function GetCUID() { return [CUID] });\n")