By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

How to print raw string data from a variable

P: 6
Could someone (anyone) give me a clue how to display all characters stored in a string variable.

For example, if I have a text file containing '1\n2\n3\n'
I read it in with A=file.read()

Now I would like python to print A as 1\n2\n3\n and not
1
2
3

Do I have to convert A to a raw string, or does it already contain raw data that is then processed by the print statement?

Do raw strings exist seperately from 'normal' strings, or is it just a string displayed in its entirety?

Thanks
Jun 29 '07 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Could someone (anyone) give me a clue how to display all characters stored in a string variable.

For example, if I have a text file containing '1\n2\n3\n'
I read it in with A=file.read()

Now I would like python to print A as 1\n2\n3\n and not
1
2
3

Do I have to convert A to a raw string, or does it already contain raw data that is then processed by the print statement?

Do raw strings exist seperately from 'normal' strings, or is it just a string displayed in its entirety?

Thanks
Expand|Select|Wrap|Line Numbers
  1. >>> s = '1\n2\n3\n'
  2. >>> print repr(s)
  3. '1\n2\n3\n'
  4. >>> 
Jun 29 '07 #2

P: 6
Expand|Select|Wrap|Line Numbers
  1. >>> s = '1\n2\n3\n'
  2. >>> print repr(s)
  3. '1\n2\n3\n'
  4. >>> 
repr() , I've not seen that before

Thanks that's great.
Jun 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.