The file executing

Benjamin musiccomposition at gmail.com
Mon Jul 9 14:29:15 CEST 2007


On Jul 9, 6:42 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Fri, 06 Jul 2007 17:15:22 -0300, Benjamin <musiccomposit... at gmail.com>  
> escribió:
>
> >> > > > How does one get the path to the file currently executing (not the
> >> > > > cwd). Thank you
> > So:
> > if __name__ == "main":
> >     currentDir = os.path.dirname(sys.argv[0])
> > else:
> >     currentDir = os.path.dirname(__file__)
>
> I think you meant to test for "__main__", but anyway, this should be  
Yes
> enough:
> currentDir = os.path.dirname(__file__)
> or perhaps os.path.dirname(os.path.abspath(__file__)). Try to determine  
> that early in your program because __file__ may contain a relative path  
> (and will give a wrong result after changing the current directory).
I do it right at the top of the first module. Thanks for the help.
>
> --
> Gabriel Genellina





More information about the Python-list mailing list