Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用该函数os.listdir(path)从运行脚本的目录中获取文件列表,但是如何在“路径”参数中说出当前目录?
os.listdir(path)
使用 os.curdir,然后如果你想要一个完整的路径,你可以使用 os.path 中的其他函数:
import os print os.path.abspath(os.curdir)
您通常会os.listdir('.')用于此目的。如果您需要标准模块,则该变量os.curdir可用。
os.listdir('.')
os.curdir
您还可以使用该getcwd()功能
getcwd()
os.getcwd() >>> 'C:\\Python25'