[Tutor] python function to know the path of the program in execution *

Spoorthi spoorthi.ms at gmail.com
Fri Feb 5 13:06:09 CET 2010


sys.path[0] should be serving the purpose effectively I guess

On Fri, Feb 5, 2010 at 5:29 PM, Rohit Roger$ <rohitraj007 at gmail.com> wrote:

> Answer :
>  >>> import sys
> >>> rohit = sys.argv[0]
> >>> print rohit
>  it returns the name of the path
>
> On Fri, Feb 5, 2010 at 4:13 PM, David Hutto <dwightdhutto at yahoo.com>wrote:
>
>>  Junk Score: 2 out of 10 (below your Auto Allow threshold<https://www.boxbe.com/mail-screening>)
>> | Approve sender <https://www.boxbe.com/anno?tc=1529381613_418589136> | Block
>> sender <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b> | Block
>> domain <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b&dom>
>>
>>
>>
>> --- On *Fri, 2/5/10, nikunj badjatya <nikunjbadjatya at gmail.com>* wrote:
>>
>>
>> From: nikunj badjatya <nikunjbadjatya at gmail.com>
>> Subject: [Tutor] python function to know the path of the program in
>> execution
>> To: tutor at python.org
>> Date: Friday, February 5, 2010, 5:08 AM
>>
>> Hi ,
>> Is there any python function to know the path of the python program under
>> execution.?
>> If someone executes a program , he should come to know the path of the
>> program..!!
>> ex. suppose a user ABC is running prog.py which is in ~ directory, the
>> user currently is in XYZ directory.
>> [ ABC at localhost XYZ ]$ python ~/prog.py
>> The program's location is ~/prog.py
>>
>> This should be the outcome of the program.
>>
>> I tried with os.getcwd()
>> os.getcwd() will return /path/to/folder/XYZ.
>>
>> Any suggestions?
>>
>> Thanks,
>> Nikunj Badjatya
>> Bangalore, India
>>
>> -----Inline Attachment Follows-----
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org<http://mc/compose?to=Tutor@python.org>
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>> I think this is what you want:
>>
>> >>> import sys
>> >>> sys.argv[0]
>> 'C:\\Python26\\testingscripts\\lowdir.py'
>> >>>
>>
>> David
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Spoorthi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100205/caa5deb7/attachment.htm>


More information about the Tutor mailing list