Text IO Wrapper Error

Hi all, im writing a script that opens only files with determinate extension. I use expandPath method to open local path ‘//’ but when i use the method open(path) it says "TypeError: Can’t convert ‘_io.TextIOWrapper’ object to str implicitly.

I thought that wasa problem caused by double slash ‘\’ used by os and slash ‘/’ used by open() method, so i tried replace() method, but doesn’t works anyway. The path string is ‘C:/users…/gamepath/file.txt’

Code is:

class ObjList(types.KX_GameObject):    
    def __init__(self, own):

    def drawObjects(self):
        gamepath = logic.expandPath('//')
        files = os.listdir(gamepath)
        for file in files:
           self.file_comp = file.split('.')
           ext = self.file_comp[1]
           if ext == 'txt':
               openFile = gamepath+file
               self.openFile = openFile.replace('\\', '/')
'+open(self.openFile, 'r'))

Ok just resolved by myself; it was just the sum of string+file, im an idiot. :smiley: