(Derivative of Winston's answer)
pathlib makes it easy to manipulate the module's filename:
pathlib
import __main__ from pathlib import Path main_name = Path(__main__.__file__).stem