您的当前位置:首页正文

怎么更改python的默认路径

来源:花图问答

可以通过os模块来实现python中路径的更改。

(推荐教程:)

os.chdir() 方法用于改变当前工作目录到指定的路径。如果允许访问返回 True , 否则返回False。

查看默认路径:

>>> import os
>>> os.getcwd()

'D:\\Program Files\\Python35'

更改默认路径:

>>> os.chdir("D:\Program Files\Python35\modifyPath\test02")
>>> os.getcwd()

'D:\\Program Files\\Python35\\ modifyPath \\ test02