PortablePython을 내 시스템에 설치하기 만하면 PHP에서 python 스크립트를 실행할 수 있고 디렉토리의 모든 파일을 나열하는 아주 기본적인 코드 (아래) 그러나 일본어 파일 이름에서는 작동하지 않습니다. 그것은 영어 파일 이름과 잘 작동하지만, 디렉토리에 일본어 문자를 포함하는 파일을 넣을 때 오류 (아래)가 발생합니다.
Python과 glob을 사용하지 않고 Windows에서 일본어 파일을 읽는 중
import os, glob
path = 'G:\path'
for infile in glob.glob(os.path.join(path, '*')):
print("current file is: ", infile)
내가 그것을 뱉어 명령 프롬프트 또는 PHP에서 'PortablePython \ 응용 프로그램 \의 python.exe를 "test.py"를'실행하려고하지만 때, 'PyScripter - Portable.exe'를 사용하여 잘 작동 다음과 같은 오류 아웃 :
current file is: Traceback (most recent call last):
File "test.py", line 5, in <module>
print("current file is: ", infile)
File "PortablePython\App\lib\io.py", line 1494, in write
b = encoder.encode(s)
File "PortablePython\App\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 37-40: character maps to <undefined>
내가 ... 파이썬에 아주 새로운 해요 그냥 Windows에서 유니 코드 파일 이름을 읽을 수 없습니다와 PHP의 문제를 해결하기 위해이 사용하고 그래서 나는 이 일이 정말로 필요합니다. 당신이 저에게 줄 수있는 도움은 위대 할 것입니다.
역 추적을 읽고'glob'는 작동하지만'print'는 그렇지 않습니다! –