简体   繁体   中英

How to get characters like '┌' and '─' on ubuntu?

I have both Windows and Ubuntu on my computer, and I am using python3 on my Ubuntu. I am pretty new with python programming, and here is the problem:

if access == 1:
print("\n" * 100)
print("┌──────────────────────────────┐")
time.sleep(0.1)
print("│                              │")
time.sleep(0.1)
print("│  Welcome to the Viktoracri   │")
time.sleep(0.1)
print("│       system database        │")
time.sleep(0.1)
print("│                              │")
time.sleep(0.1)
print("├──────────────────────────────┤")
time.sleep(0.1)
print("│                              │")
time.sleep(0.1)
print("│ Logged in as: %s             │" % u)
time.sleep(0.1)
print("│                              │")
time.sleep(0.1)
print("│ You are now logged in to the │")
time.sleep(0.1)
print("│ Viktoracri system database.  │")
time.sleep(0.1)
print("│  

If this helps, I have this at the top of the script:

#!/usr/bin/python
# -*- coding: latin-1 -*-

Those characters, '┐' and '│' does behave very strangly when I run the code.

在此处输入图片说明

Please help? The characters I have is from the Windows character map.

Your terminal is set to latin-1 (or ISO-8859-1 on my box):

>>>print "├──────────────────────────────┤".decode('iso8859')
ââââââââââââââââââââââââââââââââ¤


>>>print "├──────────────────────────────┤".decode('utf8')
├──────────────────────────────┤

See the repl.it: Python2 Python3

The fix is to change your terminal encoding so it displays the characters properly. I can replicate/fix your issue locally by swapping my terminal encoding between utf-8 & latin-1

You can try changing the encoding of the stdout

import sys
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)

if that doesn't work ,you may try changing the environment variable "PYTHONIOENCODING" to "utf_8."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM