["python"]
Is module __file__ attribute absolute or relative?

I'm having trouble understanding __file__. From what I understand, __file__ returns the absolute path from which the module was loaded. I'm having problem producing this: I have a abc.py with one statement print __file__, running from /d/projects/ python abc.py returns abc.py. running from /d/ returns projects/abc.py. Any reasons why?
__file__ is guaranteed to be an absolute path in Python 3.9+. In Python 3.4 (changelog) Module __file__ attributes (and related values) should now always contain absolute paths by default, with the sole exception of __main__.__file__ when a script has been executed directly using a relative path. In Python 3.9 (changelog): ... the __file__ attribute of the __main__ module became an absolute path From the documentation: The pathname of the file from which the module was loaded, if it was loaded from a file. The __file__ attribute may be missing for certain types of modules, such as C modules that are statically linked into the interpreter. For extension modules loaded dynamically from a shared library, it's the pathname of the shared library file. From the mailing list thread linked by @kindall in a comment to the question: I haven't tried to repro this particular example, but the reason is that we don't want to have to call getpwd() on every import nor do we want to have some kind of in-process variable to cache the current directory. (getpwd() is relatively slow and can sometimes fail outright, and trying to cache it has a certain risk of being wrong.) What we do instead, is code in site.py that walks over the elements of sys.path and turns them into absolute paths. However this code runs before '' is inserted in the front of sys.path, so that the initial value of sys.path is ''. For the rest of this, consider sys.path not to include ''. So, if you are outside the part of sys.path that contains the module, you'll get an absolute path. If you are inside the part of sys.path that contains the module, you'll get a relative path. If you load a module in the current directory, and the current directory isn't in sys.path, you'll get an absolute path. If you load a module in the current directory, and the current directory is in sys.path, you'll get a relative path.