Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] inline script write to file

edited January 2014 in OpenSesame

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

  • edited 1:53AM

    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

  • edited 1:53AM

    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

  • edited 1:53AM

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

Sign In or Register to comment.