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()

Advertisements

0 Responses to “remove line numbers from python”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Blog Stats

  • 225,320 hits

%d bloggers like this: