Python module sys in sikuli does not work

Asked by xseniya on 2018-10-03

help me please...

my sikuli script:

import os
import sys

logfile = open(sys.path[0] + 'LOGtest.txt', 'w')

when i try do it in sikuli IDE - it work ok and logfile create
but when i try do it in pyhton like this:['C:\\Program Files (x86)\\Sikuli X\\runsikulix.cmd' , '-r', scenario])

logfile(LOGtest.txt) do not create

that is it working only in sikuli IDE

why? and how i can do it?

thank you in advance

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
xseniya (xseniya) said : #1

when i do absolutly path it working everywhere

RaiMan (raimund-hocke) said : #2

--- about logging:

--- to build an absolute path relative to your script:
os.path.join(getBundlepath(), "somename.txt") # in the folder .sikuli
os.path.join(getParentpath(), "somename.txt") # in the folder containing the .sikuli

--- to run other scripts from one main script

xseniya (xseniya) said : #3

i dont need redirecting sikuli log, i want the sikuli srcipt create txt file and write my text into it

RaiMan (raimund-hocke) said : #4

There is a userlog feature.

But if want to invent your own logging:
the other things should help.

All the best.

xseniya (xseniya) said : #5

no, no..... not a userlog feature, not a logging!

problem is it path.
if i write absolutly path: open('D:\\test\\my_txt.txt', 'w') script worked without IDE, i call it from python.
but if i write: my_txt = open(sys.path[0] + 'my_txt.txt', 'w')

why when i use sys.path my script dont work without IDE?

RaiMan (raimund-hocke) said : #6

Simply: do not rely on sys.path[0] !

Use other features (as mentioned) to get your needed pat consistently.

xseniya (xseniya) said : #7

sys.path dont work in it?
its wery's sad for me

thank you for taking the time for my question

Manfred Hampl (m-hampl) said : #8

What are the contents of your PATH setting? In many cases the first part is a system directory (without write rights for users).
Does the first part of PATH have a directory separator at the end? If not, you have to add it manually or use os.path.join.

RaiMan (raimund-hocke) said : #9

I did not say: sys.path as such is not working - of course it does!

... but the content of sys.path [0] with SikuliX might Not be what you expect in all cases.

But I am sure you will find a Solution.

xseniya (xseniya) said : #10

exist a python script that runs a sikuli script that performs certain actions and writes the text in the file.txt, that the python then reads.
All of them are stored in the same special folder with read and write access.
If I write to sikuli ".\\ file" that he creates it in the working directory of sikuli (program files(86)) but I don’t need it, I want the file to be created in the folder where it is stored

in python this method works great and sikuli IDE works too.
but i dont understand, why it dont work if sikuli script started .bat-file or python-script

xseniya (xseniya) said : #11

its happened!

solution is:
my_file = open(os.path.join(getParentPath()) + '\\' + 'test.txt', 'w')
my_file .write('Test_Ok_mother fucker')
my_file .close()

by RaiMan

thank all, i'm happy :)