0

I have an python application that need to know in which directory it founded when it run,

how can i know the running application path on windows for example when i change the directory path is changed to the new directory .

is there a way to know where is the python application run withour saving it on the beginning by os.path.abspath(os.path.dirname(file))

for example the to know where the application runs after os.chdir("c:/")

     import os 
     print os.path.abspath(os.path.dirname(__file__))
     os.chdir("c:/")
     print os.path.abspath(os.path.dirname(__file__))
AKM
  • 6,285
  • 9
  • 31
  • 34
  • possible duplicate of [finding out absolute path to a file from python](http://stackoverflow.com/questions/3283306/finding-out-absolute-path-to-a-file-from-python) – SilentGhost Oct 20 '10 at 13:07
  • Hi SilentGhost I updated my question – AKM Oct 20 '10 at 13:29

2 Answers2

1

it is contained in the __file__ variable.

But if you want to know the current working directory then you should use os.getcw.

>>> os.getcwd()
'C:\\Program Files\\Python31'
>>> os.chdir(r'C:\\')
>>> os.getcwd()
'C:\\'
SilentGhost
  • 307,395
  • 66
  • 306
  • 293
0
import os
print os.path.abspath(os.path.dirname(__file__))

edit : little late !!! :) edit2 : in C# u can use the property AppDomain.CurrentDomain.BaseDirectory so using something like this will help http://pythonnet.sourceforge.net/readme.html

jknair
  • 4,709
  • 1
  • 17
  • 20