0

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.

J. Rautava
  • 64
  • 1
  • 10
  • As far as I know, the core issue is the lack of good unicode support in SikuliX. If you are flexible with the tools and on Windows, you can use [SeeShell plus Python](https://github.com/A9T9/SeeShell/tree/master/Python) instead. It has full Unicode support. – Fabrice Zaks Oct 23 '18 at 09:11
  • Thanks, I'm working on Ubuntu 16.04 so it seems I have to just live with this lack of special characters. This lack of Unicode support is really annoying since it makes life a lot harder when making something with Nordics – J. Rautava Oct 24 '18 at 11:28

1 Answers1

0

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.

J. Rautava
  • 64
  • 1
  • 10