Read special characters from .txt file in python

前端 未结 3 502
滥情空心
滥情空心 2021-01-19 21:56

The goal of this code is to find the frequency of words used in a book.

I am tying to read in the text of a book but the following line keeps throwing my code off:

3条回答
  •  一个人的身影
    2021-01-19 22:25

    Try:

    def parseString(st):
        st = st.encode("ascii", "replace")
    
        # rest of code here
    

    The new error you are getting is because you are calling isalpha on an int (i.e. a number)

    Try this:

    for ch in st:
        ch = str(ch)
        if (n for n in (1,2,3,4,5,6,7,8,9,0) if n in ch) or ' ' in ch or ch.isspace() or ch == u'\xe9':
    
            print (ch)
    

提交回复
热议问题