ROT13 in Python
Patr1ck has posted instructions on performing ROT13 in Ruby. Colin has responded with the Perl version. Here’s the Python version.
import codecs
rot13ed_data = codecs.getencoder(‘rot13’)(data_to_rot13)[0]
That is all.
Patr1ck has posted instructions on performing ROT13 in Ruby. Colin has responded with the Perl version. Here’s the Python version.
import codecs
rot13ed_data = codecs.getencoder(‘rot13’)(data_to_rot13)[0]
That is all.
January 31st, 2007 at 09:26:25
If you want a command line script, is there a better way to handle the input argument than this?
#! /usr/bin/python
# Usage:
# rot13.py ‘Hello, my name is Bob!’
import sys
import codecs
data_to_rot13 = str(sys.argv[1:])
rot13ed_data = codecs.getencoder(‘rot13’)(data_to_rot13)[0]
print rot13ed_data
Also, this live preview thing is neat. Is that a plugin?
January 31st, 2007 at 11:47:23
Python rocks my friend…thanks for convincing me. Used SWIG for the first time in the last few days…check it out.
January 31st, 2007 at 15:56:58
[quote=”Dan H”]If you want a command line script, is there a better way to handle the input argument than this?
data_to_rot13 = str(sys.argv[1:])[/quote]
First,
str(some_list)
applied to a list will get you the repr of it:The correct way is ‘ ‘.join.
Even so, I generally use optparse for such things, even if I’m not going to have options, unless it’s a one-off script that I don’t care about.
The advantage of this is that I can easily add options later.
[quote]Also, this live preview thing is neat. Is that a plugin?[/quote]
Aye. It’s called Live Comment Preview.
January 31st, 2007 at 18:39:06
It’s even shorter in vim: g?G
February 2nd, 2007 at 12:00:35
#!/bin/sh
echo $1 | tr A-Za-z N-ZA-Mn-za-m