小编Tun*_* Ha的帖子

在python中更改当前工作目录

我在桌面上创建了一个名为"headfirstpython"的文件夹,我需要将当前的工作目录更改为该文件夹及其内部的子文件夹.我使用os.getcwd()获取当前文件夹,它给了我'C\Python32'.我使用os.chdir('../ headfirstpython/chapter3')来更改目录,但它告诉它无法找到路径

>>> import os
>>> os.getcwd()
'C:\\Python32'
>>> os.chdir('../headfirstpython/chapter 3')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
os.chdir('../headfirstpython/chapter 3')
WindowsError: [Error 3] The system cannot find the path specified:         '../headfirstpython/chapter 3'
>>> os.chdir('../headfirstpython/chapter3')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
os.chdir('../headfirstpython/chapter3')
WindowsError: [Error 3] The system cannot find the path specified:   '../headfirstpython/chapter3'
>>> 
Run Code Online (Sandbox Code Playgroud)

python

11
推荐指数
1
解决办法
3万
查看次数

标签 统计

python ×1