1

So I was working on a ST2 plugin, and needed to get the current path, so I did:

import os
os.getcwd()

I was surprised that it returned C:\Windows\System32 .. Instead I had to do something like:

import sublime
dir = sublime.packages_path()
package_path = os.path.join(dir, 'NAME_OF_YOUR_PACKAGE')

I'm looking for an explanation as to why the System32 path is returned.

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
motatoes
  • 828
  • 11
  • 26
  • 1
    Apparently `System32` was the working directory of your python process. What did you expect `getcwd()` to return? – Robᵩ Apr 02 '13 at 18:50
  • @Robᵩ Wouldn't **C:\Program Files\Sublime Text 2** make more sense? – motatoes Apr 02 '13 at 19:06
  • @potatoes No, it does not. That's where the program installed. Why should it be the working directory? A sensible alternative could have been the home of the user(something like `C:/Documents and Settings/` maybe... I always forgot the windows hierarchy). – Bakuriu Apr 02 '13 at 19:12
  • @Bakuriu Ahhh, I see now. – motatoes Apr 02 '13 at 19:18

1 Answers1

1

getcwd() will return Python's current working directory. Not the directory where your script is running from.

shellster
  • 1,091
  • 1
  • 10
  • 21
  • If you are looking for the current executing script's directory, then take a look at this question: http://stackoverflow.com/questions/4934806/python-how-to-find-scripts-directory Also, you might be interested in the inspect module. – shellster Apr 02 '13 at 20:00