0

I wanted to make a fancy welcome message for my calculator when i import my calcintro.py it gives me this message:

SyntaxError: Non-ASCII character '\xe2' in file calcintro.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

I have read other StackOverflow posts for solutions but they didn't help much. Any help would be highly appreciated. Heres the code:

# coding: utf-8
# -*- coding: utf-8 -*-



print" ▄████▄   ▄▄▄       ██▓     ▄████▄     ▄▄▄      ▓█████▄  ██▒   █▓\n"
print"▒██▀ ▀█  ▒████▄    ▓██▒    ▒██▀ ▀█    ▒████▄    ▒██▀ ██▌▓██░   █▒\n"
print"▒▓█    ▄ ▒██  ▀█▄  ▒██░    ▒▓█    ▄   ▒██  ▀█▄  ░██   █▌ ▓██  █▒░\n"
print"▒▓▓▄ ▄██▒░██▄▄▄▄██ ▒██░    ▒▓▓▄ ▄██▒  ░██▄▄▄▄██ ░▓█▄   ▌  ▒██ █░░\n"
print"▒ ▓███▀ ░ ▓█   ▓██▒░██████▒▒ ▓███▀ ░   ▓█   ▓██▒░▒████▓    ▒▀█░  \n"
print"░ ░▒ ▒  ░ ▒▒   ▓▒█░░ ▒░▓  ░░ ░▒ ▒  ░   ▒▒   ▓▒█░ ▒▒▓  ▒    ░ ▐░  \n"
print"  ░  ▒     ▒   ▒▒ ░░ ░ ▒  ░  ░  ▒       ▒   ▒▒ ░ ░ ▒  ▒    ░ ░░  \n"
print"░          ░   ▒     ░ ░   ░            ░   ▒    ░ ░  ░      ░░  \n"
print"░ ░            ░  ░    ░  ░░ ░              ░  ░   ░          ░  \n"
3
  • Can you double-check that your text editor actually saves the file as UTF-8? Commented May 8, 2017 at 11:56
  • Seems about right. imgur.com/a/6mw2t Commented May 8, 2017 at 11:59
  • Any feedback on the provided solution? Commented May 9, 2017 at 11:10

1 Answer 1

1

In Python 2.7 it's necessary to explicitly use Unicode string literals in source code.

Prefix strings that contain Unicode characters with a small u.

# -*- coding: utf-8 -*-

print u" ▄████▄   ▄▄▄       ██▓     ▄████▄     ▄▄▄      ▓█████▄  ██▒   █▓"
print u"▒██▀ ▀█  ▒████▄    ▓██▒    ▒██▀ ▀█    ▒████▄    ▒██▀ ██▌▓██░   █▒"
print u"▒▓█    ▄ ▒██  ▀█▄  ▒██░    ▒▓█    ▄   ▒██  ▀█▄  ░██   █▌ ▓██  █▒░"
print u"▒▓▓▄ ▄██▒░██▄▄▄▄██ ▒██░    ▒▓▓▄ ▄██▒  ░██▄▄▄▄██ ░▓█▄   ▌  ▒██ █░░"
print u"▒ ▓███▀ ░ ▓█   ▓██▒░██████▒▒ ▓███▀ ░   ▓█   ▓██▒░▒████▓    ▒▀█░  "
print u"░ ░▒ ▒  ░ ▒▒   ▓▒█░░ ▒░▓  ░░ ░▒ ▒  ░   ▒▒   ▓▒█░ ▒▒▓  ▒    ░ ▐░  "
print u"  ░  ▒     ▒   ▒▒ ░░ ░ ▒  ░  ░  ▒       ▒   ▒▒ ░ ░ ▒  ▒    ░ ░░  "
print u"░          ░   ▒     ░ ░   ░            ░   ▒    ░ ░  ░      ░░  "
print u"░ ░            ░  ░    ░  ░░ ░              ░  ░   ░          ░  "

The newline \n however is implicit in what print does, you don't need to write it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.