How to get full path to script?

Mike Driscoll kyosohma at gmail.com
Mon Jun 9 10:42:49 EDT 2008


On Mon, Jun 9, 2008 at 12:37 AM, bukzor <workitharder at gmail.com> wrote:
> On Jun 8, 12:52 pm, kj <so... at 987jk.com.invalid> wrote:
>> In <Bu2dnUy5AvRQtdHVnZ2dnUVZ_tqdn... at comcast.com> "Mark Tolonen" <M8R-yft... at mailinator.com> writes:
>>
>> >import os
>> >print os.path.abspath(__file__)
>>
>> Great.  Thanks!
>>
>> Kynn
>>
>> --
>> NOTE: In my address everything before the first period is backwards;
>> and the last period, and everything after it, should be discarded.
>
> Note that this doesn't quite work for symbolic links or compiled
> scripts, depending on your requirements.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

For my compiled scripts, I usually use this variation:

path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0])))

It's always worked for me.

Mike



More information about the Python-list mailing list