This way makes your program non OS dependant.
from os import remove
from sys import argv
remove(argv[0])
Bonus points:
When parsing arguments the very first argument that you get in sys.argv is equals to “path-to-filename/filename.py“
More Related Contents:
- How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
- How to clear the interpreter console?
- How to start a python file while Windows starts?
- Run Python script without Windows console appearing
- Popen waiting for child process even when the immediate child has terminated
- How can I find where Python is installed on Windows?
- Python: how to kill child process(es) when parent dies?
- Python method for reading keypress?
- Compulsory usage of if __name__==”__main__” in windows while using multiprocessing [duplicate]
- What version of Visual Studio is Python on my computer compiled with?
- Using subprocess to run Python script on Windows
- Python worker failed to connect back
- mixed slashes with os.path.join on windows
- Running powershell script within python script, how to make python print the powershell output while it is running
- How to handle a signal.SIGINT on a Windows OS machine?
- python’s webbrowser launches IE, instead of default browser, on Windows relative path
- Tensorflow r1.0 : could not a find a version that satisfies the requirement tensorflow
- IOError: [Errno 13] Permission denied when trying to open hidden file in “w” mode
- How do I eliminate Windows consoles from spawned processes in Python (2.7)? [duplicate]
- How to get the text cursor position in Windows?
- How to install lxml on Windows
- Pyodbc error Data source name not found and no default driver specified paradox
- chcp 65001 codepage results in program termination without any error
- Error: No module named ‘fcntl’
- ‘pip setup.py bdist_wheel’ no longer builds forced non-pure wheels
- Add “django-admin.py” path to command line on Windows 7
- multiprocessing: How can I ʀᴇʟɪᴀʙʟʏ redirect stdout from a child process?
- Python long filename support broken in Windows
- Detecting computer/program shutdown in Python?
- Python file.write creating extra carriage return