Reputation: 1779
How can I format my string such that \r
is included in the output rather than being interpreted as a carriage return?
I am building a long string with formatting entities in it like \n
and \t
, hence I want to preserve the printing output that I get with the below.
s1 = ("""
WITH (
DATA_SOURCE = 'MyAzureStorage',
FORMAT = 'CSV',
FIRSTROW = 2,
FIELDTERMINATOR=',',
DATAFILETYPE='char',
ROWTERMINATOR='\r',
TABLOCK)
""")
print(''.join(s1))
Upvotes: 0
Views: 537
Reputation: 3061
Use an r-string:
s1 = r"""
WITH (
DATA_SOURCE = 'MyAzureStorage',
FORMAT = 'CSV',
FIRSTROW = 2,
FIELDTERMINATOR=',',
DATAFILETYPE='char',
ROWTERMINATOR='\r',
TABLOCK)
"""
print(''.join(s1))
Upvotes: 1
Reputation: 700
Use repr function it returns a string containing a printable representation of an object.
s1 = ("""
WITH (
DATA_SOURCE = 'MyAzureStorage',
FORMAT = 'CSV',
FIRSTROW = 2,
FIELDTERMINATOR=',',
DATAFILETYPE='char',
ROWTERMINATOR='\r',
TABLOCK)
""")
print(repr(s1))
Or use additional backward slash
ROWTERMINATOR='\\r',
Upvotes: 1