7
$\begingroup$

I am writing a Quake 1 .BSP import script with python and I want to extract the textures from the .BSP so that the mesh can be textured. However, the textures are paletized (instead of a color, only an index into a palette is stored for each pixel) and the palette is not contained in the .BSP.

I'd like to include the palette in a file with my script, and load it from the script at run time. However, I don't know how to get the path to the palette file, so I can't load it. Is there a way to get the path my script is running in? I've tried using just the file name of the palette, but it didn't work.

p.s. I know I could store the palette in a python file, but I'd rather use the original .PAL format so that users can swap it for another palette if desired.

$\endgroup$
8
$\begingroup$

Python has a built-in __file__ global to access the path a script is running at. You can use it in your script by using this code snippet:

import os
script_directory = os.path.dirname(os.path.abspath(__file__))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.