Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 744641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:00:07+00:00 2026-05-14T09:00:07+00:00

This is my code: print ‘哈哈’.decode(‘gb2312’).encode(‘utf-8’) …and it prints: SyntaxError: Non-ASCII character ‘\xe5’ in

  • 0

This is my code:

print '哈哈'.decode('gb2312').encode('utf-8')

…and it prints:

SyntaxError: Non-ASCII character '\xe5' in file D:\zjm_code\a.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

How do I print ‘哈哈’?

Update: When I use the following code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

print '哈哈'

… it prints 鍝堝搱. That isn’t what I wanted to get.

My IDE is Ulipad, is this a bug with the IDE?

Second Update:

This code will print the characters right:

#!/usr/bin/python
# -*- coding: utf-8 -*-


print u'哈哈'.encode('gb2312')

…and when I use this:

#!/usr/bin/python
# -*- coding: utf-8 -*-

a='哈哈'
print a.encode('gb2312')
Traceback (most recent call last):
  File "D:\zjm_code\a.py", line 5, in <module>
    print a.encode('gb2312')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

…or…

#!/usr/bin/python
# -*- coding: utf-8 -*-

a='哈哈'
print unicode(a).encode('gb2312')
Traceback (most recent call last):
  File "D:\zjm_code\a.py", line 5, in <module>
    print unicode(a).encode('gb2312')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

…it doesn’t work. How would I print the variable a appropriately?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:00:07+00:00Added an answer on May 14, 2026 at 9:00 am

    You first need to declare an encoding, as the error messages says so clearly — it even tells you to look here for details! Your encoding is presumably gb2312.

    BTW, it would be simpler (with the same encoding declaration) to do

    print u'哈哈'.encode('utf-8')
    

    and you may not even need the encode part, if your sys.stdout has an encoding attribute properly set (depends on your terminal, OS, etc).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering why this code section prints out the following: print request.user.has_perm('bug_tracking.is_developer'): + str(request.user.has_perm('bug_tracking.is_developer'))
I expected this code to print 'Same 1' and 'Same2', but it prints only
I used this code to print the current page: <form> <input type=button value=Print onClick=window.print();
Why does this code not print an exception stack trace? public class Playground {
I'm having a problem with getting this code to print out to file due
When I try this code: if Verbose: print("Building internam Index for %d tile(s) ..."
This code gives me an empty result. I expect it to print out the
I have this code: def display(self): print self.doc.toprettyxml(indent= ) strigName ='/Users/my_user/Desktop/python/' + str(datetime.datetime.now()) +
I have this code in Python inputted = input(Enter in something: ) print(Input is
So I wrote this code in java. It should print Mouse Click when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.