简体   繁体   中英

Python - How would a person open every .ppm file in a directory

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")

I am trying to open all .ppm files in a user given directory.

You keep trying to open a file named "r". Try adding the filename.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM