2016-11-02 3 views
0
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 파일을 열려고합니다.Python - 디렉토리에서 .ppm 파일을 열 때 어떻게하나요?

+0

'open ("r", encoding = "utf-8")은 무엇을해야합니까? 당신은 파일을 열지 않고 모드와 인코딩만을 전달합니다 ... – Pythonista

+0

'ppm'은 이미지 파일입니까? 그렇다면 이미지 파일 작업을위한 베개와 같은 이미지 처리 모듈을 사용할 수도 있습니다. – Marcin

답변

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

고마워요! 나는 뭔가를 놓친다는 것을 알았다. –

+0

제쳐두고, 나는 .ppm이 ascii가 아니라 utf-8이라는 것을 확신합니다. – tdelaney