How to get the path of current running python script?

Kevin Yuan farproc at gmail.com
Tue Dec 20 07:48:15 EST 2005


Oh, my god! I forgot that python is written in C!

int main(int argc, char* argv[])
{
    printf(argv[0]);
    return 0;
}

*argv[0]* also woks here!!
:) :) :)
Thank you very much!!

2005/12/20, Tim Williams (gmail) <tdwdotnet at gmail.com>:
>
>
> On 20/12/05, Kevin Yuan <farproc at gmail.com> wrote:
> >
> > I tried the following
> >
> > >>>> getFilePath = lambda name: os.path.normpath('%s\\%s' % (sys.modules[name].prefix,
> > sys.modules[name].__name__))
> > >>>> getFilePath('__main__')
> >
>
>
> getFilePath =  sys.argv[0]    ??
>
>
> :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051220/22c04788/attachment.html>


More information about the Python-list mailing list