pycharm console unicode to readable string
Question: studying python with [this
tutorial](http://www.youtube.com/watch?v=ZxiJ92-4Qys&index=5&list=WL)

The problem is when i trying to get cyrillic characters i get unicode in
pycharm console.

![enter image description here](http://i.stack.imgur.com/QpiHD.png)

    
    
    import requests
    from bs4 import BeautifulSoup
    import operator
    import codecs
    
    def start(url):
        word_list = []
        source_code = requests.get(url).text
        soup = BeautifulSoup(source_code)
    
        for post_text in soup.findAll('a', {'class': 'b-tasks__item__title js-set-visited'}):
            content = post_text.string
    
            words = content.lower().split()
            for each_word in words:
                word_list.append(each_word)
        clean_up_list(word_list)
    
    
    
    def clean_up_list(word_list):
        clean_word_list = []
        for word in word_list:
            symbols = "!@#$%^&*()_+{}|:<>?,./;'[]\=-\""
            for i in range(0, len(symbols)):
                word = word.replace(symbols[i], "")
            if len(word) > 0:
                clean_word_list.append(word)
        create_dictionary(clean_word_list)
    
    
    
    def create_dictionary(clean_word_list):
        word_count = {}
    for word in clean_word_list:
        if word in word_count:
            word_count[word] += 1
        else:
            word_count[word] = 1
    
    for key, value in sorted(word_count.items(), key=operator.itemgetter(1)):
        print(key, value)
    

When i am changing **print(key, value)** to **print(key.decode('utf8'),
value)** i am getting "UnicodeEncodeError: 'ascii' codec can't encode
characters in position 0-7: ordinal not in range(128)"

![enter image description here](http://i.stack.imgur.com/ua9Bx.png)

start('<https://youdo.com/tasks-all-opened-all-moscow-1>') There is some
suggestion on the internet about changing encoding in some files - don't
really get it. Can't i read it in console? OSX

**UPD** key.encode("utf-8") ![enter image description
here](http://i.stack.imgur.com/pcURT.png)


Answer: UTF-8 is sometimes painful. I created a file with a line in Latin caracters
and another one with Russian ones. The following code:

    
    
    # encoding: utf-8
    
    with open("testing.txt", "r", encoding='utf-8') as f:
        line = f.read()
        print(line)
    

outputs in PyCharm

![enter image description here](http://i.stack.imgur.com/wfVSw.png)

Note the two `encoding` entries

Since you are getting data from a web page, you must make sure that you use
the right encoding as well. The following code

    
    
    # encoding: utf-8
    r = requests.get('http://www.pravda.ru/')
    r.encoding = 'utf-8'
    print(r.text)
    

outputs in PyCharm as

![enter image description here](http://i.stack.imgur.com/3neW2.png)

Please note that you must specifically set the encoding to match the one of
the page.

