2.53 open() acting strangely?

I’ve been trying to read from a text file to load data, ect. Python no longer treats the .blend location as the default directory, opting instead for the main blender folder. Also, it doesn’t seem to want to notice a file even exists, unless it has made the file itself.
e.g. I tried just loading from a text file in the correct location, IOError, no such file exists. I run a different script to create a text file of the same name(deleting the first one before running) and then change the contents of the text file. try the first program again, and it has no problem with seeing the file…

I can work around the “unable to read files unless created by python” glitch, but I’m going to have trouble if it always treats the main Blender directory as the default file location.

anyone have any suggestions on circumventing the first problem, and or any explanation for the second?(a fix would be nice too ;))

If I’m not mistaken, when a blend file is loaded from Blender (IE you open Blender, and then open the file via recent documents or just navigating to it) then it treats the Blender directory as the root- but if you open the file from the OS by double-clicking it (or hitting enter, or whatever), or export the file to an executable and then run that, it treats the file directory as root.

Would you look at that, not only did opening the .blend file first work for the directory problem, it also fixed the script’s ignorance of files not created by itself… Thanks Captain!

GameLogic.expandPath should get you the .blend file directory.

in 2.53, use bge.logic.expandPath("//") to get the .blend directory.

Edit: BTW, you must import bge for this to work.