gpt4 book ai didi

Python:如何在 shell 中找到当前工作目录?

转载 作者:行者123 更新时间:2023-11-28 22:48:21 25 4
gpt4 key购买 nike

os.path.dirname(os.path.realpath(__file__)) 会找到你当前的工作目录,但是如果我运行的是 python shell,__file__未定义,因此该方法抛出异常。

如何在 Python shell 中找到当前工作目录?

运行:Windows 7、Python 3.3、VirtualEnv

最佳答案

使用 os.getcwd()功能:

>>> import os
>>> os.getcwd()
'/home/univerio'

关于Python:如何在 shell 中找到当前工作目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25213867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com