with open("C:scripts/CUAppVersion.js", 'a') as file:
file.write("if [CUID] = -1 then"
"function GetCUID() { return 0; }"
"else"
"function GetCUID() { return [CUID] });")
That is my code and it succesfully puts the JS into the JS file but it puts it on one line rather than as I typed it above. I am aware that my JS code isn't fully correct I do need to fix it.
How do I put that code into the JS file with the correct layout?
3 Answers 3
Use multiline strings.
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())
answered Jul 1, 2016 at 16:02
Rokas Kupstys
6194 silver badges8 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Jill
Thank you that did the job! :D
What about adding some endlines \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")
answered Jul 1, 2016 at 16:01
Mohamed Moanis
5077 silver badges18 bronze badges
1 Comment
Jill
Thanks a mill, can't believe I didn't think of that xD
Add \n to the end of every line.
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")
answered Jul 1, 2016 at 15:59
Alen Androsevic
971 silver badge7 bronze badges
1 Comment
Jill
Thank you, can't believe I over looked such a simple solution.
default