howto obtain directory where current (running) py-file is placed?

Stef Mientki S.Mientki-nospam at mailbox.kun.nl
Thu Jun 7 19:01:09 EDT 2007


Gerard Flanagan wrote:
> On Jun 7, 8:39 am, dmitrey <open... at ukr.net> wrote:
>> Hi all,
>> I guess this question was asked many times before, but I don't know
>> keywords for web search.
>>
>> Thank you in advance, D.
> 
> import os
> 
> d1 = os.path.dirname(__file__)
here I get an error "__file__" is not defined ??
> d2 = os.path.dirname(os.__file__)
here I get a completely different path ??
> 
> print d1
> print d2

This seems to work (but I doubt it's always working !! )
print os.getcwd()

so what's the real answer ?

thanks,
Stef Mientki




More information about the Python-list mailing list