The Python Oracle

Get name of current script in Python

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Book End

--

Chapters
00:00 Question
00:26 Accepted answer (Score 891)
00:52 Answer 2 (Score 212)
01:16 Answer 3 (Score 142)
08:13 Answer 4 (Score 69)
08:51 Thank you

--

Full question
https://stackoverflow.com/questions/4152...

Accepted answer links:
[__file__]: https://docs.python.org/reference/import...

Answer 3 links:
[official documentation]: https://docs.python.org/3/reference/data...
[From ]: https://docs.python.org/3/whatsnew/3.4.h...
[issue 18416]: https://bugs.python.org/issue18416
[main module]: https://docs.python.org/3/library/__main...
[From ]: https://docs.python.org/3.9/whatsnew/3.9...
[issue 20443]: https://bugs.python.org/issue20443
[official documentation]: https://docs.python.org/3/library/sys.ht...
[another answer to this question]: https://stackoverflow.com/a/4152992/3903...
[py2exe]: http://www.py2exe.org/
[PyInstaller]: http://www.pyinstaller.org/
[inspect]: https://docs.python.org/3/library/inspec...
[another answer to this question]: https://stackoverflow.com/a/47120068/390...
[inspect.currentframe()]: https://docs.python.org/3/library/inspec...
[inspect.getfile(...)]: https://docs.python.org/3/library/inspec...
[inspect.getsourcefile(...)]: https://docs.python.org/3/library/inspec...
[raises a TypeError exception]: https://www.oreilly.com/library/view/pyt...
[this answer to another question]: https://stackoverflow.com/a/6761378/3903...
[another answer to this question]: https://stackoverflow.com/a/62119753/390...
[lib_programname]: https://github.com/bitranox/lib_programn...
[pytest]: https://docs.pytest.org/
[pydoc]: https://docs.python.org/3/library/pydoc....
[os.path.abspath(...)]: https://docs.python.org/3/library/os.pat...
[os.path.realpath(...)]: https://docs.python.org/2/library/os.pat...
[os.chdir(...)]: https://docs.python.org/3/library/os.htm...
[os.path.basename(...)]: https://docs.python.org/3/library/os.pat...
[os.path.splitext(...)]: https://docs.python.org/3/library/os.pat...
[Python 3.4]: https://docs.python.org/3/whatsnew/3.4.h...
[PEP 428]: https://www.python.org/dev/peps/pep-0428
[PurePath]: https://docs.python.org/3/library/pathli...
[pathlib]: https://docs.python.org/3/library/pathli...
[pathlib.PurePath(...).name]: https://docs.python.org/3/library/pathli...
[pathlib.PurePath(...).stem]: https://docs.python.org/3/library/pathli...

Answer 4 links:
[__main__]: http://docs.python.org/3/library/__main_...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #scripting #basename

#avk47