2

I tried with:

dir = os.path.dirname(".")

And the return is empty.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Yan Zhao
  • 359
  • 4
  • 15
  • Possible duplicate of ["Find current directory and file's directory"](https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory) –  Nov 25 '17 at 16:41
  • 1
    Possible duplicate of [Find current directory and file's directory](https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory) – klutt Nov 25 '17 at 16:42
  • 2
    `dirname` doesn't even look at the file system; it is purely a string operation on a file path that (roughly) drops the part after the last `/`. – chepner Nov 25 '17 at 16:45

2 Answers2

4

abspath should do the trick:

dir = os.path.abspath('.')
Mureinik
  • 297,002
  • 52
  • 306
  • 350
3

Use abspath:

dir = os.path.abspath('.')

or for the current working directory

dir = os.path.getcwd()
Daniel
  • 42,087
  • 4
  • 55
  • 81