Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing unescaped white space to shell

Consider this line of Python code:

s = "This string has \n\r whitespace"

How do I make

print s

give me

This string has \n\r whitespace

instead of

This string has
whitespace

as it does now.

like image 371
Trindaz Avatar asked Oct 12 '11 18:10

Trindaz


People also ask

How to print blank space in shell script?

3 Answers. Show activity on this post. ~> myVar="Hi, there!"; printf '%20s\n' "$myVar" Hi, there! ~> myVar="Bye!"; printf '%20s\n' "$myVar" Bye!

How do I show space in bash?

Type df and press enter in a Bash terminal window to get started. You'll see a lot of output similar to the screenshot below. Using df without any options will display the available and used space for all mounted filesystems. At first glance, it might look impenetrable, but it is quite easy to understand.

Is white space ignored in Python?

Other languages mostly ignore whitespaces, Python doesn't.

What is white space in Python?

What are whitespace characters in Python? In Python, characters that are used for spacing are called as whitespace characters. They include newline, spaces, tabs, carriage return, feed, etc. Whitespace is a string that has been pre-initialized and is used as a string constant.


1 Answers

do you want a raw string ?

s = r"This string has \n\r whitespace"

or to transform special characters to it's representation?

repr(s)
like image 69
Michał Šrajer Avatar answered Oct 02 '22 22:10

Michał Šrajer