[solved] inline script write to file
Hy There,
thx for the 0.26 version, looks great!
I'm trying to write informations to a .txt file using an inline script, containing some variables and other stuff.
openSesame returns a SyntaxError when i add a line break to file.write(str). Using the same line on command line works well however.
command line:
f = open(filename, 'w')
f.write("text.txt") #works
f.write("text.txt\n") # works also
openSesame:
f = open(filename, 'w')
f.write("text.txt") #works
f.write("text.txt\n") # doesn't work -> SyntaxError: EOL while scanning string literal
I have tried several options, but none works.
Thx in advance!
Cheers, Björn
Comments
Hi Björn,
Ah, yes. It's kind of annoying, but OpenSesame doesn't play nice with newlines (also see this discussion). Fortunately, in inline_scripts the workaround is quite simple. Instead of typing '\n' directly, you use ord(10), like so:
f.write("text.txt"+ord(10))Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
thank you so much for quick response!
I have used
f.write("text.txt"+ord(10)), but openSesame stills return an error, unfortunately it doesn't explicite it. Instead i tried
f.write("text.txt"+chr(10)), and now openSesame writes to the file with line breaks :-)
Thx for the inspiration!
Cheers! Björn
Ow right, yes, of course! ord() makes a number from a character, and chr() makes a character from a number. I mixed this up, but I meant chr(10).
Check out SigmundAI.eu for our OpenSesame AI assistant!