首页 > 文章列表 > 怎么更改python的默认路径

怎么更改python的默认路径

Python 默认路径
320 2022-08-07

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

(推荐教程: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