How to get a script's home directory?

There must be an easy answer to this question - how can I figure out what directory a script is in from within python?



take a look at “Blender.Get(…)”.
There are several keywords to get information about the current configuration.
Maybe you can find the information you need.


It seems to only be info about directories you’ve already set in Blender…

It seems like a very simple thing - I can’t find anything in the Python docs, either!

from Blender import Text

for t in Text.Get():
  print 'The text\'s name is', t.getName()
  print 'The text\'s filename is', t.getFilename()

Hope this helps.

[edit] Oh yeah, almost forgot.

I haven’t testet if it works inside Blender, but it should give you some ideas. Here’s a python script that should print out it’s location. Paste it to a new python file and start it with “python” on the command line:

# Print out the absolute path to the script

import sys
import os

print sys.path[0] + os.sep + sys.argv[0]

sys.path[0] is the path to the script, os.sep is the separator, sys.argv[0] is the name of the script.

Blender always reports sys.path and sys.argv as the path to the Blender executable. Hence, you’ll have to use the prescribed methods to get the script name and path.