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?

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())
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")

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")

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.