2014-07-16 4 views
1

블로그의 기사에 대한 정보가 들어있는 파일을 읽는 간단한 스크립트를 작성했습니다. 파일의 각 행은 하나의 기사에 해당하며 탭으로 구분 된 열은 기사 'ID', 제목 및 단락과 같은 정보를 보유합니다.IDLE에서이 스크립트를 실행할 때 오류가 발생하지 않는 이유는 무엇입니까?

# Open file and skip first line(headers) 
file = open("RBArticlesTabClean.txt", "r", encoding="utf-8") 
file.readline() 
# Read and decode whole file 
articlesFile = htmlcodes.decodeString(file.read()).lower() 
# Split file into its lines 
articlesFileList = articlesFile.split("\n") 

이 작동되어 있고 프로그램이 파일을 읽고 있는지 테스트하려면 각 문서는 목록의 요소가되도록

id title paragraph 
1 Motorola prototypes from Frog Some cool looking concepts for phones, watches etc 
2 Digital everything This new york times article talks about the willingness of consumers 
3 E-mails banned at summer camps E-mails compound feelings of homesickness in kids 
4 Simple Multimedia Websites/e-mail This is a sort of website/e-mail generation site 
5 Campground wi-fi Wi-fi is now on the list of amenities offered at many campgrounds 
6 Fog screen Literally, a screen made by projecting onto fog 

이 코드는 '\ n을'하여 파일을 분할 제대로, 내가 얻은 기사의 목록을 반복하고, 전체를 인쇄 : 예상대로

for each in articlesFileList: 
    input(each) 

IDLE이 실행, 그것은, (소문자) 각 라인을 인쇄 작품마다 사용자를 enter 키를 누릅니다. 스크립트 명령 프롬프트를 실행하면

그러나,이 오류와 함께 세 개의 기사를 인쇄 한 후 실패

1) 왜 내가 이것을받을 않습니다

Traceback (most recent call last): 
    File "E:\Python\RBTrends\RBTrendsAnalysis.py", line 52, in <module> 
    print(each) 
    File "C:\Python34\lib\encodings\cp850.py", line 19, in encode 
    return codecs.charmap_encode(input,self.errors,encoding_map)[0] 
UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 89: character maps to <undefined> 

나는이 개 질문이 오류?

2) IDLE 및 명령 프롬프트에서 프로그램을 실행하는 것과 다른 점은 무엇입니까?

+0

[UnicodeEncodeError : 'charmap'코덱은 인코딩 할 수 없습니다 - 문자 매핑은 , 인쇄 기능] (http://stackoverflow.com/questions/14630288/unicodeencodeerror-charmap-codec-cant-encode-character) -maps-to-undefined) – perreal

답변

1

내가 아는 한 IDLE은 유니 코드 문자를 표시 할 수 있지만 명령 프롬프트는 평범한 오래된 ASCII 문자보다 나은 것을 할 수 없다. 그것이이 오류가 발생하는 이유입니다.

+0

그건 의미가 있습니다. 약간 성가시다. 개인적으로, 나는 IDLE이 일관성을 유지하기 위해 유니 코드를 표시 할 능력이 없다고 생각했다. – xander

+0

하하! 유감스럽게도 새로운 스마일/캐릭터가 격일로 자르면 유니 코드를 무시할 수 없습니다. 유니 코드 IDE를 그렇게하는 것이 낫습니다. – user2963623

관련 문제