Help in rotate 13 program
Sayantan Datta
kenzo.zombie at gmail.com
Thu Dec 29 06:48:28 EST 2011
please help me, this code doesn't work,
the output file comes out to be empty. How do i fix it? and where is it
going wrong?
==============rot13.py==============
#!/usr/bin/env python
import sys
import string
CHAR_MAP=dict(zip(string.ascii_lowercase, string.ascii_lowercase[13:26] +
string.ascii_lowercase[0:13]))
def rotate13_letter(letter) :
"""
Return the 13-char rotation of a letter
"""
do_upper = False
if letter.isupper() :
do_upper = True
letter = letter.lower()
if letter not in CHAR_MAP :
return letter
else :
letter = CHAR_MAP[letter]
if do_upper :
letter=letter.upper()
return letter
if __name__ == '__main__' :
for line in sys.stdin :
for char in line :
sys.stdout.write(rotate13_letter(char))
===========sample.html===========
<html>
<head>
<title> Hello, World! </title>
</head>
<body>
<p>
Hi there, all of you earthlings
</p>
<p>
Take us to your leader.
</p>
</body>
</html>
===============TERMINAL============
this is what i run in the terminal,
cat sample.html | python rot13.py rot13.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111229/c2d461ad/attachment-0001.html>
More information about the Python-list
mailing list