I want to get the path of invoked (top-level) Python script. Actually it is a package and I am running it with python3 -m <package-name>. I researched web and Stack Overflow but couldn't find a proper solution. __file__ and __path__ are not working, os.getcwd() doesn't work if the package is invoked from another location, sys.argv[0] is not guaranteed to have the full path. The way import __main__ is not a good way I think since I import the top-level script into a dependent script.
I encountered the problem of open("xyz.dat","r") not finding xyz.dat in the same folder as the .py file
Solved my problem by adding "working_dir": "$file_path" to my Sublime Text 3 build script.
However, I wondered how python libraries did it.  For example, Kivy's AsyncImage has a "source" parameter to its constructor that successfully finds image files in the same folder as the top-level py file.
After some digging, I discovered the method that Kivy uses:

import kivy.resources as kr
full_path = kr.resource_find("image.png")

I do not like to rely on a setting in a build script to find files in the same folder, so this is the method I'm going to follow in future Kivy projects.
BTW, resource_find does rely on sys.argv[0] to "know" the full path of the top-level python script.
Getting path of the top-level Python script