Answer the question
In order to leave comments, you need to log in
How to achieve the same unicode handling of a Python script in the console and in Spyder (IDE)?
There is a Python script that parses several tens of thousands of pages. Debugging and running this code in Spyder runs without any errors. Pages are parsed correctly, and the script is working successfully.
In the console, running the same script invariably throws errors like
"UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-4: ordinal not in range(128)"
How can I achieve the same script behavior in Spyder and in the console?
Ubuntu 12.10 system. Console locale:
LANG=en_US.UTF-8
LANGUAGE=en_US:UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=
Spyder with default settings.
The script uses unicode by default:
# -*- coding: utf-8 -*-
Answer the question
In order to leave comments, you need to log in
Replace
all constructions of the form with
(I assume that all your strings are Unicode)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question