Print full ascii art
Solution 1
encode
takes a string and encodes it into bytes. That's not what you want here; you want to just print the string directly:
print("""\
._ o o
\_`-)|_
,"" \
," ## | ಠ ಠ.
," ## ,-\__ `.
," / `--._;)
," ## /
," ## /
""")
If this doesn't work, your terminal is most likely not configured to display Unicode. Unfortunately, I am not particularly knowledgeable about terminal configuration; Why doesn't my terminal output unicode characters properly? may be relevant, but my ability to help is mostly limited to the Python side of things.
Solution 2
print(r"""\
._ o o
\_`-)|_
,"" \
," ## | ಠ ಠ.
," ## ,-\__ `.
," / `--._;)
," ## /
," ## /
""")
The r allows you to print raw text better especially when there is a lot of inverted commas in the picture that you are trying to print.
Solution 3
print(r"""\
._ o o
\_`-)|_
,"" \
," ## | ಠ ಠ.
," ## ,-\__ `.
," / `--._;)
," ## /
," ## /
""")
print(r"""\
._ o o
\_`-)|_
,"" \
," ## | ಠ ಠ.
," ## ,-\__ `.
," / `--._;)
," ## /
," ## /
""")
Solution 4
I get "...codec can't encode character '\u0ca0' in position..."
If print(giraffe)
fails due to an incorrect character encoding then try to set PYTHONIOENCODING
environment variable correctly e.g., in bash:
$ PYTHONIOENCODING=utf-8 python3 -c 'from text_art import giraffe as s; print(s)'
Do not use print(giraffe.encode('utf-8'))
:
print()
function expects a text, not bytes (unrelated: to print bytes, you could usesys.stdout.buffer.write(some_bytes)
)- how bytes are interpreted as a text is the property of your terminal, you shouldn't hardcode its settings in your code.
PYTHONIOENCODING
allows you to change the encoding if necessary
Solution 5
print(r"""\
._ o o
\_`-)|_
,"" \
," ## | ಠ ಠ.
," ## ,-\__ `.
," / `--._;)
," ## /
," ## /
""")
this will type or print this in raw text
user3476998
Updated on August 25, 2021Comments
-
user3476998 over 2 years
I am trying to print ascii art like this:
print(("""\ ._ o o \_`-)|_ ,"" \ ," ## | ಠ ಠ. ," ## ,-\__ `. ," / `--._;) ," ## / ," ## / """).encode('utf-8'))
And the output does not look right at all.
What is the proper method of printing ascii art?