[英]Why can't I find or locate a '.txt' filetype created by python on the current working directory?
[英]Why can't I change the current working directory?
我正在尝试创建我的第一个 python 程序,该程序删除d:\\source
任何空目录。 看来我现在的技能连目录都进不去:
import os
os.getcwd()
os.chdir("D:\\SOURCE")
os.getcwd()
我得到的只是...
D:\CODING\venv\Scripts\python.exe D:/CODING/tester.py
Process finished with exit code 0
似乎它没有改变工作目录,我该如何验证? 为什么它根本不显示os.chdir("D:\\\\SOURCE")
或第二个os.getcwd()
命令的结果/错误?
您的程序可能确实更改了目录。 但是你看不到这个:
os.getcwd()
不会做任何可见的事情:它检索当前工作目录并丢弃它。 相反,你应该做print(os.getcwd())
您需要打印结果。
import os
print(os.getcwd())
os.chdir("D:\\SOURCE")
print(os.getcwd())
os.chdir()不返回任何值。 它只会改变目录。 正如其他答案中所建议的,您可以使用打印/输出当前目录
os.chdir("D:\\SOURCE")
print(os.getcwd())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.