2024-05-31 23:50:59 发布
网友
我一直假设sys.path中的第一个条目默认是当前工作目录。但事实证明,在我的系统中,第一个条目是脚本所在的路径。因此,如果我执行的脚本位于/usr/bin中,则sys.path中的第一个条目是/usr/bin。是我的系统配置错误,还是这是预期的行为?在
sys.path
/usr/bin
这是设计的:
As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter.
path[0]
来源:http://docs.python.org/library/sys.html#sys.path
您可以使用os.getcwd()获取当前目录。在
os.getcwd()
这是设计的:
来源:http://docs.python.org/library/sys.html#sys.path
您可以使用
os.getcwd()
获取当前目录。在相关问题 更多 >
编程相关推荐