3

I'm searching for a way to get the path of the directory of the file that I have chosen by QFileDialog.getOpenFileName(). I know that you can access it by os.path.dirname(os.path.realpath(filename), but I'm searching for a better way because I need to work in this directory. I don't really understand why you can access the file by open(filename, 'r') though your current working directory (when typing print(os.getcwd()) is not the directory of the file. Maybe there is a way by accessing something like the current working directory of the Qt.Application, but I had no success..

Also I have functions where you need arg1 = directory and arg2 = filename1 (in the directory) as arguments. Funnily enough they suddenly seem to work with just(!) arg1 = 'C:' as directory and arg2 = filename2 when filename2 is the file I've accessed by QFileDialog.getOpenFileName().

I'm happy about any explanation!

niemmi
  • 17,113
  • 7
  • 35
  • 42
jule
  • 61
  • 1
  • 5

1 Answers1

3

It turns out that the filename which is accessed by QFileDialog.getOpenFileName() is actually not only the filename but the whole path..

jule
  • 61
  • 1
  • 5