Reputation: 15
I am trying to write a string converted from a tuple to a file where after the string ends I wish to input a new line but using \n I came across an error.
Ms = 2
Mbh = 4.3e6
Msu = Ms/Mu
Mbu = Mbh/Mu
n = 1
test = '"scattter -n',n,'-A 0.005 -g 1e-5 -t 100000 -i "-M',Mbu,' -rm 3 -R 0 -v 0.0.86680911331878907 -t-q 0.5 -a 1.0 -e 0 -r1 9.8863538914005233E-003 -t1 -q 1 -a 6.2500000000000000E-002 -e 0 -r1 9.8863538914005233E-003 -r2 9.8863538914005233e-003"'
string = str(test)
f = open("set1_M2.dat", 'w')
f.write(string\n) #New line
f.write("n, Mbu, Msu\n")
f.write(str([n, Mbu, Msu]))
f.close()
And here is the traceback that I get when I run this error:
f.write(string\n)
^
SyntaxError: unexpected character after line continuation character
I am not sure on how to combat this, I have tried to adjust the quotations on the string but the original "test" needs to stay the same.
Upvotes: 0
Views: 1582
Reputation: 73444
Did you try:
f.write("\n")
?
This says to write the newline to file f
. Read more here: writing string to a file on a new line everytime?
Upvotes: 1