P3D and External Data Handling

Does P3D have a set of APIs that handle external file tasks suck as opening, reading and writing to files?

I know python can handle this, but if you’re aiming for an application that can cross platform, the python will lead you to scripting Platform based external calls; and Windows file path syntax will not work for Mac and Linux.

Just use the “open” as usual. Else you can use the virtual file system afaik but I am not sure if this allows access to “external files” too. Panda paths looks like “/c/” instead of “C:/” (as an example). But in any case (vs and “normal” open) you can stick with relative paths (with slashes) which are unified for the most common oses.

Panda and Python use a different approach to solving the pathname differences between Windows and Unix/Mac.

Python solves this problem by providing a set of tools in os.path to operate on pathnames according to the local convention. Thus, os.path.join(‘root’, ‘models’, ‘maps’) produces the string “root/models/maps” on Linux and “root\models\maps” on Windows. If you use Python’s built-in open() commands, you should follow Python’s conventions and always use os.path to construct your pathnames.

Panda solves this problem by asking everyone to use Panda-style filenames, which looks a lot like Unix-style filenames, no matter what platform they are on. Thus, to use Panda’s API’s for reading files, you would use Filename(‘root/models/maps’) on both Linux and Windows. To use Panda’s interfaces for reading and writing, you can use methods on Filename or VirtualFileSystem.

Another solution is to put “from stdpy.file import open” at the top of your Python file. This replaces open() with a new version that understands Panda filename syntax on any platform. So now you can use open(‘root/models/maps/t.txt’, ‘r’) on any system and it will work on Windows and on Linux. It can also read files out of the vfs as well as real files on disk. This happens automatically when you are running in a p3d file.


This only works with P3D packages, right? As I can’t find any module with that name. The API references it, but it seems it doesn’t show the full path. Anyway, just importing stdpy or panda3d.stdpy doesn’t work.

Sorry, I meant direct.stdpy.file. My mistake. In general, “direct.stdpy” contains several modules that redefine or reimplement standard Python modules for greater Panda compatibility; thus the name.


This is great. thanks!