Using open( ), where to find the output file?

Asked by John

I'm using the Python function open( ) to create and write to a .txt file, but where is this .txt file located?

Example SikuliX code:

with open('output.txt', 'w') as f:
    for k in range(n):
        f.write(c_str[k] + '\n')

I'm using a Mac.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
John
Solved:
Last query:
Last reply:
Revision history for this message
John (aeronautix1) said :
#1

I'm running from the IDE, not the terminal.

Revision history for this message
John (aeronautix1) said :
#2

Running from terminal solved my problem.

For reference:

java -jar /Applications/SikuliX.app/Contents/Java/sikulix.jar

Revision history for this message
John (aeronautix1) said :
#3

The output file is created in your user directory.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

the best way always is, to decide for a folder yourself.

e.g the folder containing the script you are running:

dir = getParentPath()

with open(os.path.join(dir, 'output.txt'), 'w') as f:

here you find some more convenience functions for folder handling:
http://sikulix-2014.readthedocs.io/en/latest/scripting.html#file-and-path-handling-convenience-functions

Revision history for this message
John (aeronautix1) said :
#5

Thanks, that helped a lot.