1

I want to display the following text in my program.When ever I paste the following text in python it interprets backslash as escape sequence and mess ups my ascii art..any idea to get this solved geeks.Here is the text I want to appear in my program

  _  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__ \
 |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                              |___/         |___/     
1
  • 1
    You could also store this in a text file and have your program read it from the file. This makes that part easier for a non-programmer to maintain Jun 27, 2012 at 10:42

3 Answers 3

8

You can use raw strings:

myString = r'''_  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__ \
 |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                          |___/         |___/'''
# note the r before the string starts

More Info

Try testing the difference between print '\tHello, world!' and print r'\tHello, World!'

1
  • Just read that link and realised it didn't really say much on it - sorry! The r before the beginning of the string literal prevents the backslash character from escaping. It's especially useful when your writing regular expressions.
    – DanielB
    Jun 27, 2012 at 10:51
3

use triple quotes, place this text between """ """

>>> strs="""_  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__ \
 |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                              |___/         |___/     """
>>> print(strs)
_  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__  |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                              |___/         |___/   
1
ascii_art = r"""_  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__ \
 |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                              |___/         |___/     """
print ascii_art

Use r"""text""" to avoid backslashes escaping EOL's.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.