Linux application deployment

Robert Brewer fumanchu at amor.org
Mon Sep 6 18:06:53 CEST 2004


Alex Martelli wrote:
> Robert M. Emmons <RobMEmmons at cs.com> wrote:
>    ...
> > One thing I've always wonders was -- Is there a way for a 
> python module
> > to tell where it's file is located???  If you could do this 
> it might 
> 
> Piece of cake: the key part of this recipe is
>     def whereami(): return sys.modules[__name__].__file__
> then you can os.path.abspath this filename string as you wish.
> 
> Here's a more complete example foo.py:
> 
> #!/usr/bin/env python
> 
> import sys, os
> 
> def whereami(): return os.path.abspath(sys.modules[__name__].__file__)

Shorter version for the local directory:

import os.path
localDir = os.path.dirname(__file__)

I don't see any reason to make it a callable...?


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list