I try to get paths into list and everything is working just fine until I get special characters like ä
or ö
. In string they are represented as bytes for example ä
is \xe4
. If I use same Python script in Terminal I get all paths printed out correctly even though paths in list contain these bytes instead of actual letters.
Here is my code where I extract all the filenames:
def read_files(path):
"""
Read all files in folder specified by path
:param path: Path to folder which contents will be read
:return: List of all files in folder specified by path
"""
files = []
for f in listdir(path):
if isfile(join(path, f)):
files.append(make_unicode(join(path, f)))
return files
def make_unicode(string):
if type(string) != unicode:
string = string.decode('utf-8')
return string
I don't have any idea where to go from now on. I have tried practically everything I possibly could find from Google. This is more of a SikuliX problem than Python, because Python code works just fine outside SikuliX.
I use Python 2.7 and SikuliX 1.1.1.
So I got this covered. Problem was, that read_files(path)
function was called again later and when the path
was unicode with special characters marked as bytes the whole thing broke. I changed my code in a fashion that this function was called only once and then I was able to work with special characters.