Unfortunately, I seem to recall being frustrated by this at some point, because for what seems to be a very simple problem, there isn't a very simple solution. There's a lot of different ways to go about it, but each seems to have some issues:
__file__ isn't always defined (forget exactly what situations it won't exist) sys.argv[0] often doesn't have any path info os.getcwd() can vary - you don't have to be in the same cwd as the script you're running I think the 'most' reliable solution I found was: import inspect print inspect.getsourcefile( lambda:None ) (grabbed from this thread: http://mail.python.org/pipermail/python-list/2003-December/242365.html - jason.osipa was also hinting this way, I think) However, I think there are situations where this can fail, too (again, don't remember exactly - I think when using .pyc's, that have subsequently moved, perhaps? I remember that was tripping up one of these methods, anyway.) 2009/4/24 Bård Henriksen <[email protected]>: > > use __file__ > > eg: > > def get_my_path(): > """ > Return the path to wherever this script file is stored > """ > return os.path.dirname(__file__) > > Bård > > > > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/python_inside_maya -~----------~----~----~----~------~----~------~--~---
