File path in Python using Blenderplayer?

I have a blend that I run with Blenderplayer. This blend loads an external text file with python:
inp = file(“messages.txt”,“r”)
The text file location is next to the blend file. It is ok when I start the game from Blender.
But when I start blend from Blenderplayer I need to move the text file next to Blenderplayer.exe.

And how it works on Linux or Mac? I have only Windows.

bge.logic.expandPath("//") returns the absolute path to the current file execute. If it still gives you the path to the bplayer, just do open(bge.logic.expandPath("//myfolder//textcontnainer//") + “message.txt”, “rt”)

It should be similar functionality on Mac and Linux.

Thank you, but I use 2.49.

Then it’s
in 2.49. Maker’s correct, though - the principle is the same.

thank you, it is working :slight_smile: