I'm creating a Python program for Ubuntu, and I need to write a python script into a file, but the \n
in the code creates a new line in the file, it isn't copied as \n
, so I get an EOL error.
This is the code for the Python script:
#!/usr/bin/env python3
import os
import sys
home = os.environ["HOME"]
name = sys.argv[1]; command = sys.argv[2]
launcher = ["[Desktop Entry]", "Name=resolutionx", "Exec=/bin/bash resolutionx.sh", "Type=Application", "X-GNOME-Autostart-enabled=true"]
file = home+"/.config/autostart/"+name.lower()+".desktop"
if not os.path.exists(file):
with open(file, "wt") as out:
for l in launcher:
l = l+name if l == "Name=resolutionx" else l
l = l+command if l == "Exec=/bin/bash resolutionx.sh" else l
out.write(l+"\n")
else:
print("file exists, choose another name")
In this part:
if not os.path.exists(file):
with open(file, "wt") as out:
for l in launcher:
l = l+name if l == "Name=resolutionx" else l
l = l+command if l == "Exec=/bin/bash resolutionx.sh" else l
out.write(l+"\n")
The code for writing the above to the file is:
fStartUpScript = open("set_startupscript.py", "w")
fStartUpScript.write("""
#!/usr/bin/env python3
import os
import sys
home = os.environ["HOME"]
name = sys.argv[1]; command = sys.argv[2]
launcher = ["[Desktop Entry]", "Name=resolutionx", "Exec=/bin/bash resolutionx.sh", "Type=Application", "X-GNOME-Autostart-enabled=true"]
file = home+"/.config/autostart/"+name.lower()+".desktop"
if not os.path.exists(file):
with open(file, "wt") as out:
for l in launcher:
l = l+name if l == "Name=resolutionx" else l
l = l+command if l == "Exec=/bin/bash resolutionx.sh" else l
out.write(l+"\\n")
else:
print("file exists, choose another name")""")
fStartUpScript.close()
How can I solve this?
The essential information is currently missing however.
I have nothing to say more, so I can't say it's related to Ubuntu yet – Maythux Jun 25 '15 at 14:55\\n
– Byte Commander Jun 25 '15 at 15:14\n
is not written, but actually creates a new line. – TellMeWhy Jun 25 '15 at 18:20