26
May
09

remove line numbers from python


When you copy-paste code from some snippet, you’ll sometimes copy the line numbers as well. So, to remove them, I’ve wrote this script :


import sys
import re

def remove_line_numbers(line):
  components = re.split("\s+",line)
  if(re.search("\d+:?",components[0])):
    return " ".join(components[1:])
  else:
    return line

if __name__ == "__main__":
	file = sys.argv[1]
	fhnd = open(file,"r")
	for line in fhnd:
	  line = remove_line_numbers(line)
	  print line
	fhnd.close()


0 Responses to “remove line numbers from python”



  1. No Comments Yet

Leave a Reply