-3

I want to print some ASCII art using python 3 on my terminal. I've tried triple quotes but got all sorts of Syntax Errors. How would you do this?


EDIT:

Let's take a very good ASCII ART, we want to print it on our terminal. Temptative example program::

print('''\

        .$$$$$:$$$:$$$$$$$     _..._        .$$$SSSSSS$$$$$$$$$.
       .$$$$$:$$$$:$$$$$$$    ~.sggg.        "  .~(g )$$$$$$$$$$.
       $$$$$:$$$$$:$$$$$$$ .sS$$$$$$$$s.     : '"--"' `$$$$$$$$$$.
       `$$$:$$$$$$:$$$$$$$.$$" .. g"-. `.    `.-.._    `$$$$$$$$$$
        $$$:$$$$$$:$$$$$$$`$' ' `._.'   :      `---      $$$$$$$$$.
        $$$:.$$$$$:$$$$$$$    `---'  _.'                 $$$$$$$$$$$.
        $$$$$:$$$$:$$$$$$s      ----"           .        $$$$$$$$$$$$.
        $$$$$`.$$$:$$$$$$$.                      `-._   .$$$$$$$$$$$$$$Sss.
        $$$$$$`;$$:$$$$$$$$.         _.:         .'   ;  $$$$$$$$$$$$$$$$$$$.
       .s$$$$$$'$$`.$$$$$$$$.      .'  `.       ' _ .`.  $$$$$$$$$$$$$$$$$$$$Ss.
     .s$$$$$$$$$$$$:$$$$$$$$$     :  _   ~~-...'.'.'  :  $$$$$$$$$$$$$$$$$$$$$$$
   .s$$$$$$$$$$$$$$`.$$$$$$$$s      : .~-,-.-.~:'.'   :  $$$$$$$$$$$$$$$$$$$$$$
 .s$$$$$$$$$$$$$$$$$`$$$$$$$$$$.    `  ~-.`"""'.'      `.$$$$$$$$$$$$$$$$$$$'
    ''')

Sorry if the question was not clear, I'm new.

Community
  • 1
  • 1
deppep
  • 135
  • 1
  • 1
  • 7

1 Answers1

1

The example you posted appears to print fine in both python 2.7 and python 3. It's unclear where your issue is occurring since this works fine, but for other ASCII text perhaps you are getting the error.

In order to print ASCII text that contains quotes like ' or " you need to add the triple quotes at the beginning and end of the print function to fix this.

Maybe your issue is that you don't want to have the new lines at the top and bottom of the ascii art. You need to have a space at the end to let python know it is the end of the string. For example:

print(''''art' ''')

Notice there are 3 quotes at the start and end, with a space between the last quote in the string you are printing. This removes the newline from the string.

This won't work since it does not have the space:

print(''''art'''')

To get rid of the top newline, you'll basically need to press backspace on the first line of the top of your art but preserve the spaces. It won't line up in the code, but when it prints it will line up correctly.

This code removes the top and bottom newlines. Maybe you were forgetting to add the space at the end between the quote in the ascii art and the triple quote.

mystring = '''        .$$$$$:$$$:$$$$$$$     _..._        .$$$SSSSSS$$$$$$$$$.
       .$$$$$:$$$$:$$$$$$$    ~.sggg.        "  .~(g )$$$$$$$$$$.
       $$$$$:$$$$$:$$$$$$$ .sS$$$$$$$$s.     : '"--"' `$$$$$$$$$$.
       `$$$:$$$$$$:$$$$$$$.$$" .. g"-. `.    `.-.._    `$$$$$$$$$$
        $$$:$$$$$$:$$$$$$$`$' ' `._.'   :      `---      $$$$$$$$$.
        $$$:.$$$$$:$$$$$$$    `---'  _.'                 $$$$$$$$$$$.
        $$$$$:$$$$:$$$$$$s      ----"           .        $$$$$$$$$$$$.
        $$$$$`.$$$:$$$$$$$.                      `-._   .$$$$$$$$$$$$$$Sss.
        $$$$$$`;$$:$$$$$$$$.         _.:         .'   ;  $$$$$$$$$$$$$$$$$$$.
       .s$$$$$$'$$`.$$$$$$$$.      .'  `.       ' _ .`.  $$$$$$$$$$$$$$$$$$$$Ss.
     .s$$$$$$$$$$$$:$$$$$$$$$     :  _   ~~-...'.'.'  :  $$$$$$$$$$$$$$$$$$$$$$$
   .s$$$$$$$$$$$$$$`.$$$$$$$$s      : .~-,-.-.~:'.'   :  $$$$$$$$$$$$$$$$$$$$$$
 .s$$$$$$$$$$$$$$$$$`$$$$$$$$$$.    `  ~-.`"""'.'      `.$$$$$$$$$$$$$$$$$$$' '''

print(mystring)
  • thanks a lot, triple quotes were just fine but i had some in the text that went unnoticed and interrupted the line before the art ending. – deppep Dec 19 '18 at 07:18