Are you looking for my non-technical blog?

This is now my technical-only blog, my non-technical blog is here.

07 January 2006


It is hard to write programs source code on your own blog or webpage especially when writing a language like Python where tabs and white spaces do matter. However blogs are the best place to share your coding ideas and receive comments and bugs fixes on them. So one nice idea is to replace the tab or "\t" with [TAB], and since it is really hard to do it by hand this is a python proggie to replace them automatically.
''' Pyblish - Python Publisher '''
''' Author: Tarek Amr '''
''' Version: 0.1'''
''' File:'''
''' Date: 07 Jan 2006 '''
import string, sys
if __name__ == "__main__":
[TAB][TAB]filein = sys.argv[2]
[TAB][TAB]mode = sys.argv[1]
[TAB][TAB]print "Usage: python pyblish [ --decode | --encode ] INPUT_FILE_NAME"
[TAB]if mode == "--decode":
[TAB][TAB]temp = filein.split(".")
[TAB][TAB]temp[-1] = ".txt"
[TAB][TAB]fileout = string.join(temp)
[TAB]elif mode == "--encode":[TAB]
[TAB][TAB]temp = filein.split(".")
[TAB][TAB]temp[-1] = ".py"
[TAB][TAB]fileout = string.join(temp)
[TAB][TAB]print "Usage: python pyblish [ --decode | --encode ] INPUT_FILE_NAME"
[TAB]fdin = open(filein,"r")
[TAB]fdout = open(fileout,"w")
[TAB]for line in fdin.readlines():
[TAB][TAB]if mode == "--decode":
[TAB][TAB][TAB]line = line.replace("\t","[TAB]")
[TAB][TAB]elif mode == "--encode":
[TAB][TAB][TAB]line = line.replace("[TAB]","\t")
By the way this code has nothing to do with that web server and application framework hosted at sourceforge and called Pyblish too

Tags: , ,