Printing Hidden Character in Python

Brian Mills HardToSpell at gmail.com
Fri Oct 27 10:40:43 EDT 2006


Fulvio wrote:
> ***********************
> Your mail has been scanned by InterScan MSS.
> ***********************
>
>
> On Thursday 26 October 2006 16:43, Wijaya Edward wrote:
> > How can we print out the hidden character like
> > "\n", "\r" etc in Python?
>
> If it's meant to evidentiate then you should scan each byte an print it out
> i.e.
> o = open('yourfile'.'rb')
>
> >>> o = open('paths.con','rb')
> >>> for c in o.read():
> ...  if c == '\n':
> ...   print '\\n'
> ...  if c == '\r':
> ...   print '\\r'
> ...  print c,
> ...
> unfortunately it will be a space between each letter. Maybe using
> sys.stderr.write (c) will avoid that.
>
> F

Or sys.stdout.write(c).  If efficiency is a major issue, you may also
want to look into the re module's regular expression substitution model
to get a new, converted string before printing it.




More information about the Python-list mailing list