-1

If Im in: C:\dir\pythonfile.py

when I run Path.cwd() I worry about terminal runs from different places, so (maybe wrong) I rely on Path(file)

that returns the right path with the file. If I use ".parent" I get: dir = Path(file).parent # returns C:\ NOT C:\dir\

Im stuck. Help?

Edit: If I run resolve; same problem

1 Answers1

0

Path(file) returns the directory the file is in (C:\dir in your case). Path(file).parent returns the parent of the directory, not of the file; this is C:\. Just use dir = Path(file).

Vercingatorix
  • 1,838
  • 1
  • 13
  • 22