如何使用 python os 更改驱动器? [英] How can I change drives using python os?
本文介绍了如何使用 python os 更改驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将当前目录从 C:
更改为 Y:
我试过了:
I'm trying to change the current directory from C:
to Y:
I tried:
import os
os.chdir('Y:')
但我不断收到错误消息,说它无法找到驱动器.基本上我正在寻找相当于
but I keep getting an error saying that it can't locate the drive. Essentially I'm looking for the equivalent of the
cd /d
cmd 中的命令.
推荐答案
你确定 Y:
真的是一个有效的盘符吗?
Are you sure Y:
really is a valid drive letter?
尝试 os.chdir('C:')
并确保它有效.(它对我有用.)
Try os.chdir('C:')
and make sure that works. (It works for me.)
这篇关于如何使用 python os 更改驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文