Python - 一个人如何打开目录中的每个.ppm文件

时间:2016-11-02 00:05:17

标签: python ppm

import os
import glob

path = input("Please enter the directory you want to get the files from. -> ")

for filename in glob.glob(os.path.join(path, '*.ppm')):
    open("r", encoding="utf-8")

我正在尝试打开用户指定目录中的所有.ppm文件。

1 个答案:

答案 0 :(得分:1)

您一直在尝试打开一个名为" r"的文件。尝试添加文件名。

import os
import glob

path = input("Please enter the directory you want to get the files from. -> ")

for filename in glob.glob(os.path.join(path, '*.ppm')):
    file_obj = open(filename, "r", encoding="utf-8")