草庐IT

python - Perl 的 FindBin 的 Python 等价物是什么?

这个问题在这里已经有了答案:Howdoyouproperlydeterminethecurrentscriptdirectory?(16个答案)关闭4年前。在Perl中,FindBinmodule用于定位原始脚本的目录。在Python中获取此目录的规范方法是什么?我见过的一些选项:os.path.dirname(os.path.realpath(sys.argv[0]))os.path.abspath(os.path.dirname(sys.argv[0]))os.path.abspath(os.path.dirname(__file__))