-1

I'm trying to do an ascii image in python but gives me this error

File "main.py", line 1
    teste = print('''
                  ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 375-376: truncated \UXXXXXXXX escape

And I think it's because of the U character, why that happened, is any way to solve this? ASCII image

  • 1
    Post text not images of text. – Mark Tolonen Jul 26 '22 at 23:27
  • Does this answer your question? ["Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3](https://stackoverflow.com/questions/1347791/unicode-error-unicodeescape-codec-cant-decode-bytes-cannot-open-text-file) – Numerlor Jul 26 '22 at 23:30

1 Answers1

2

You've got \U in your string, which is being interpreted as the beginning of a Unicode ordinal escape (it expects it to be followed by 8 hex characters representing a single Unicode ordinal).

You could double the escape, making it \\U, but that would make it harder to see the image in the code itself. The simplest approach is to make it a raw string that ignores all escapes save escapes applied to the quote character, by putting an r immediately before the literal:

teste = print(r'''

Note the r immediately after the (, before the '''.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271