I have the actual association part down, but when I open the file that is associated with my Python program, how do I get the filepath of the file opened?
I think it is something like sys.argv? But that just returns the path to the python program, not the associated file.
The contents of sys.argv are platform-dependent, as noted in sys.argv. I do know that
sys.argv[0]is the full path on Windows only when you open.pyfiles using the shell by double-clicking on it. Using the command line just results in the script name.The
osmodule provides platform-independent solutions. The full path to your script should always be available with the following code: