[Tutor] 'root' dir of a package from within the package ?

Dave S pythontut at pusspaws.net
Fri Jan 12 21:29:10 CET 2007


On Tuesday 09 January 2007 10:55, Michael Lange wrote:
> 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



Many thanks, 

Sorry for the delay - work got in the way :)

Cheers

Dave


More information about the Tutor mailing list