When a file executes it sets some special variables and __name__ is one of them. __name__ is set as "__main__" if it is getting executed directly. But if the file has been imported then it stores the filename suppose.
if __name__ == "__main__":
print("Executed directly", __name__ )
print("Import executed", __name__ )
### On execution of abc.py directly __name__ will store "__main__".
print "Import executed: ", __name__
### On execution of xyz.py, below output will display:
Import executed abc.py
Import executed __main__