468,257 Members | 1,429 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,257 developers. It's quick & easy.

How to print raw string data from a variable

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
2 88385
bvdet
2,851 Expert Mod 2GB
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
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.

Similar topics

3 posts views Thread by Konrad Mathieu | last post: by
2 posts views Thread by semi | last post: by
6 posts views Thread by John Aldrin | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.