怎么更改python的默认路径

Python (195) 2023-05-12 09:38:33

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

(推荐教程:Python入门教程)

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

查看默认路径:

>>>importos
>>>os.getcwd()

'D:\\ProgramFiles\\Python35'

更改默认路径:

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

'D:\\ProgramFiles\\Python35\\modifyPath\\test02
THE END

发表回复