[TriZPUG] identity crisis

John Strickler jstrick at mindspring.com
Thu Sep 5 00:59:22 CEST 2013


os.getcwd() only reports the current working directory of the script. If
the script is launched from somewhere else, it reports the "somewhere
else". That is, if you cd to /tmp, and run /some/where/else/myapp.py,
getcwd() returns "/tmp", which won't help with Laura's problem.

I can't make __file__ have a null string on my Linux box, but for all other
cases you can use os.path.abspath(), which will provide the full path given
a relative path.

--John Strickler



On Wed, Sep 4, 2013 at 6:10 PM, Steve Gambino <stevegambino at gmail.com>wrote:

> Laura,
>
> import os
> os.getcwd()  # will return the current working directory
>
> Is that what you are looking for?
> Steve
>
>
>
>
>
> On Wed, Sep 4, 2013 at 5:10 PM, Laura Tateosian <lgtateos at ncsu.edu> wrote:
>
>> I'd like to get the path of the current file, so that I can append the
>> sys.path and then import user-defined modules based on relative paths.
>>
>> sys.argv[0] can do this. But sometimes it returns just the file base name
>> or an empty string, depending on how the script is run. The same goes for
>> __file__
>>
>> Is there a simple reliable approach for determining the full path file
>> name of the script I'm inside?
>>
>> Thanks,
>> Laura
>> ______________________________**_________________
>> TriZPUG mailing list
>> TriZPUG at python.org
>> https://mail.python.org/**mailman/listinfo/trizpug<https://mail.python.org/mailman/listinfo/trizpug>
>> http://trizpug.org is the Triangle Zope and Python Users Group
>>
>
>
> _______________________________________________
> TriZPUG mailing list
> TriZPUG at python.org
> https://mail.python.org/mailman/listinfo/trizpug
> http://trizpug.org is the Triangle Zope and Python Users Group
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/trizpug/attachments/20130904/496f4122/attachment-0001.html>


More information about the TriZPUG mailing list