[Tutor] 'root' dir of a package from within the package ?
Michael Lange
klappnase at freenet.de
Tue Jan 9 11:55:10 CET 2007
On Mon, 8 Jan 2007 19:24:37 +0000
Dave S <pythontut at pusspaws.net> wrote:
> Hi all,
>
> I have written a python package, which works fine, the 'root' directory
> is 'my_app' with sub directories within in, complete with there __init__.py
> files.
>
> I need to work out the path to the root directory from within the app, os.path
> gives me pythons path! - oh and its in XP.
>
> Any suggestions ?
>
Hi Dave,
app_root = os.path.abspath(sys.path[0]) or, within the main executable .py file,
app_root = os.path.abspath(os.path.dirname(__file__)) should do the trick.
I hope this helps
Michael
More information about the Tutor
mailing list