你不能打开一个目录的内置函数文件().您可以创建一个过滤列表的文件在一个特定的目录中找到操作系统模块.
- >>> import os
- # Create a list of directory entries
- >>> dir_name = 'X:\\TEMP\\temp'
- >>> fList = os.listdir(dir_name)
- # The directory entries do not include the full path
- # Create a list of file names with full path, eliminating subdirectory entries
- >>> fList1 = [os.path.join(dir_name, f) for f in fList if os.path.isfile(os.path.join(dir_name, f))]
或者,你可以改变你的当前工作目录os.chdir ()你不需要访问该文件的完整路径.