Aside from the aforementioned sys.argv[0], it is also possible to use the __main__:
import __main__
print(__main__.__file__)
Beware, however, this is only useful in very rare circumstances;
and it always creates an import loop, meaning that the __main__ will not be fully executed at that moment.