1

In Python 2.7 I have the following and I debug through IDLE:

print 'Here'
import sys
reload(sys)
sys.setdefaultencoding('cp1252')
print 'There'

what I get in return is

Here

So after I have set the default encoding it does not print the desired output. Could this be due by conflicts with the IDLE encoding?

abhinav
  • 1,108
  • 11
  • 23
Thegamer23
  • 537
  • 1
  • 8
  • 20
  • Why are you doing a `reload(sys)`? – Ry- Mar 16 '17 at 11:39
  • May I ask why you need to do this? – underscoreC Mar 16 '17 at 11:42
  • I am using reload because I read it here: http://stackoverflow.com/questions/2276200/changing-default-encoding-of-python I want to change my encoding to cp1252 but if I follow the process in the link above it does not print anything else – Thegamer23 Mar 16 '17 at 11:43

1 Answers1

2

Because it is unable to find reference to setdefaultencoding from sys. That is why it is not printing 'There'

setdefaultencoding is deprecated and one should never use it!

Have a look at the following link. Why should we NOT use sys.setdefaultencoding(“utf-8”) in a py script?

Community
  • 1
  • 1
abhinav
  • 1,108
  • 11
  • 23
  • [This](http://stackoverflow.com/questions/3828723/why-should-we-not-use-sys-setdefaultencodingutf-8-in-a-py-script) is also some pretty good advice – underscoreC Mar 16 '17 at 11:46
  • Ok because I found it here: http://stackoverflow.com/questions/2276200/changing-default-encoding-of-python Is there a way to change the encoding from Python itself so that If I forward my code to a friend he is able to run it with changed charset (cp1252) – Thegamer23 Mar 16 '17 at 11:46
  • It's a trick to change default encoding using reload(sys) but it is never recommended as per the documentation! – abhinav Mar 16 '17 at 11:51