0

I have a Python project which was structured as follows:

root
 |__gui
     |__homepage.py
     |__ window.py
 |_prolog
     |_queries.py

I moved the file homepage.py into the root directory. I fixed the imports but now I can't run the file because I get an error on the paths which I shouldn't get. Therefore I wrote these two lines in the file homepage.py to see what the file sees.

import os
print(os.listdir('.'))

The expected output would be:

'gui' 'prolog'

Instead I get:

window.py

Meaning that for some reason the file still is still seen as if it was never moved. I don't know why this is happening, maybe Pycharm is caching some information about the previous structure, which should be updated. The problem is, I don't know how to do it. Can anyone help me?

1 Answers1

1

The behaviour is expected, it is just your assumption to be wrong.

The '.' points to the current working directory, which it is independent to the location of your homepage.py file. check on your run configuration where you put the working directory.

PyCharm just selects the working directory from configuration and call your /<full-path>/homepage.py, so the working directory is independent to the main script file.

Note: if you want to known the location of main file (which sometime we need), you should use sys.argv[0].

Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32