#!/usr/bin/env python
#coding=utf-8
# remove line number before copy code from other
# file
class Parser():
"""
Parse the file, and remove the line number
of given text,and remove the left and right space
"""
def __init__(self,raw):
self.raw = raw.splitlines()
self.result=[]
def remove(self):
# find lines of the file
#lines = len(self.raw)
number = 1
for line in self.raw:
line = line.lstrip().rstrip().replace(str(number),'')
self.result.append(line)
number +=1
return "\n".join(self.result)
def test():
testlines = "1 print 'hello world' \n\
2 if __name == 'main': \n\
3 print 'third line ' \n\
"
print Parser(testlines).remove()
if __name__ == "__main__":
test()
#coding=utf-8
# remove line number before copy code from other
# file
class Parser():
"""
Parse the file, and remove the line number
of given text,and remove the left and right space
"""
def __init__(self,raw):
self.raw = raw.splitlines()
self.result=[]
def remove(self):
# find lines of the file
#lines = len(self.raw)
number = 1
for line in self.raw:
line = line.lstrip().rstrip().replace(str(number),'')
self.result.append(line)
number +=1
return "\n".join(self.result)
def test():
testlines = "1 print 'hello world' \n\
2 if __name == 'main': \n\
3 print 'third line ' \n\
"
print Parser(testlines).remove()
if __name__ == "__main__":
test()