6
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?

asked Jul 1, 2016 at 15:57

3 Answers 3

9

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you that did the job! :D
2

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

1 Comment

Thanks a mill, can't believe I didn't think of that xD
0

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

1 Comment

Thank you, can't believe I over looked such a simple solution.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.