Windows命令行:切换目录并执行Python

0 投票
1 回答
1980 浏览
提问于 2025-04-18 08:53

我在Windows 7的命令提示符下执行一个Python脚本时遇到了麻烦。我尝试了很多不同的命令来运行这个脚本。不管是:

python e:\filepath\pythonScript.py
python pythonScript.py
cd\ & pythonScript.py
cd\ && e:\filepath\pythonScript.py

我总是得到相同的结果:

[Errno 2] No such file or directory

每当我使用这个命令:

dir

它会打印出C盘的内容,即使我使用的是:

cd c: && dir

如果有人能帮我解释一下如何在Windows 7中更改目录和执行Python脚本,我将非常感激。

1 个回答

1

如果你想换到一个新的驱动器,只需要输入驱动器的字母,后面加上冒号。

C:\>e:
E:\>dir


Volume in drive E has no label.
 Volume Serial Number is 9016-4EF8

 Directory of E:\
18-Apr-14  02:16 AM    <DIR>          assets
01-May-14  04:22 AM    <DIR>          store
06-Jun-14  09:32 AM                22 test.py

E:\>cd assets


E:\assets>python test.py
hello world

或者

C:\>e: && cd assets && dir
 Volume in drive E has no label.
 Volume Serial Number is 9016-4EF8

 Directory of E:\assets

或者

  C:\>e: && cd \  && cd assets && dir
       ^     ^          ^           ^
ch drive && go root&&go fldr && list foldr contents

撰写回答