I have a Python package which is organized like this:
package
|- subpackage
| |- code.py
| |- window.ui
| ...
In code.py I want to access the file window.ui via
PyQt4.uic.loadUi('window.ui', self)
This works well, if I just run code.py with subpackage as the working directory. But if I import the package from another working directory, this file cannot be found:
IOError: [Errno 2] No such file or directory: 'window.ui'
My question: How can I get the path name of the directory the file code.py is placed in, in order to create the absolute path name of window.ui. Or, how can I most efficiently access the file window.ui.
I tried os.path.abspath('.') from here, but it only returns the absolute path of the current working directory.