Created
February 16, 2012 06:36
-
-
Save shimizukawa/1842688 to your computer and use it in GitHub Desktop.
Pythonコードを任意のエンコーディングに変換。#がコメント行として扱われるエンコーディングなら動作する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: base64 | |
aW1wb3J0IHN5cwpzeXMuc3Rkb3V0LndyaXRlKCJIYXJ1byBXb3JsZCFcbiIpCg== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
prog, fname, codec = sys.argv | |
r = open(sys.argv[1]).read() | |
w = r.encode(codec) | |
f = open("%(codec)s-%(fname)s" % locals(), 'wt') | |
f.write('#coding: %(codec)s\n' % locals()) | |
f.write(w) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python hello.py | |
Haruo World! | |
$ python conv.py hello.py rot13 | |
$ python rot13-hello.py | |
Haruo World! | |
$ python base64-hello.py | |
File "base64-hello.py", line 2 | |
SyntaxError: bad argument type for built-in operation | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.stdout.write("Haruo World!\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: rot13 | |
vzcbeg flf | |
flf.fgqbhg.jevgr("Unehb Jbeyq!\a") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment