This was A Question Asked by my teacher. “How Would You Stop Your Script From Executing, IF Filenamed is renamed by User.”
I had sumthing this idea in my mind.
#consider the name of the script to be myscript.py
import os
signal = 0
while 1:
if "myscript.py" not in os.listdir("."):
signal = 1
else:
if signal:
break
else:
#do the requirements
But then He said, whatif, the user has a file named “myscript.py” already in the directory, and he changed the name of the script, the script would run well. And there I got stuck.
I am using python2.7, OS: Windows, Allowed To use Any external Libraries if required, Any suggestions?
The
__file__attribute of modules contains the full pathname of the Python script that contains it.