Printing Hidden Character in Python
Ben Finney
bignose+hates-spam at benfinney.id.au
Thu Oct 26 05:20:30 EDT 2006
[Please don't top-post replies. I've corrected it in this post.]
Wijaya Edward <ewijaya at i2r.a-star.edu.sg> writes:
> Ben Finney wrote:
> > Wijaya Edward <ewijaya at i2r.a-star.edu.sg> writes:
> > > How can we print out the hidden character like "\n", "\r" etc in
> > > Python?
> > What result do you want that you're not getting with:
> > print "\n"
>
> printing "line" will not show the hidden chars like "\n","\r".
> Is there a way to print it out?
Again, I don't know what result you want to see. The characters are
non-printable; what output do you expect?
If you want to see a Python string representation of the input, maybe
the 'repr' function is what you want.
>>> foo = "bar\tbaz\r\n"
>>> print foo
bar baz
>>> print repr(foo)
'bar\tbaz\r\n'
--
\ "The most common way people give up their power is by thinking |
`\ they don't have any." -- Alice Walker |
_o__) |
Ben Finney
More information about the Python-list
mailing list