[Tutor] program idea

lonetwin lonetwin@yahoo.com
Thu May 15 11:16:01 2003


Hey Kirk,
	Me, me, me .....me like strings and list comprehension.
On Thursday 15 May 2003 09:39 am, Kirk Bailey wrote:
> I have abn idea for a tool program.
> it would read in a script, and write it out again with a line number in a
> comment  at the end of each line, as
>
> f1=open(filename,mode)	#121
> owner=string.strip(f1.readline())	#122
> passwd=string.strip(f1.readline())	#123
> f1.close()	#123
> ##124
>
> etc.
> Line numbering gets VERY confusing if you slip up even a little when doing
> it by hand.
>
> Another would remove such and redo it when creating a new version with new
> lines in teh script.
>
> Any discussion?

def writeLineNumbers(filename):
    l = open(filename).readlines()
    l = [ l[i][:-1] + "\t#%s" % i for i in range(len(l)) ]
    open("%s.new" % filename).write("\n".join(l))

def stripLineNumbers(filename):
    l = open(filename).readlines()
    l = [ l[i][:l[i].rfind('#')] for i in range(len(l)) ]
    open("%s.new" % filename).write("\n".join(l))

howz that for obfuscated code ?? Anyway to put that open().readline() too in 
there ??

:)
Peace
Steve

 

-- 
Basically my wife was immature.  I'd be at home in the bath and she'd
come in and sink my boats.
		-- Woody Allen