Skip to content

Instantly share code, notes, and snippets.

@sanity
Created April 16, 2009 14:37
Show Gist options
  • Save sanity/96439 to your computer and use it in GitHub Desktop.
Save sanity/96439 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys,random
if (len(sys.argv) != 5):
print "Args: every input train test"
sys.exit(-1)
selectevery = int(sys.argv[1])
inputfile = open(sys.argv[2], 'r')
trainfile = open(sys.argv[3], 'w')
testfile = open(sys.argv[4], 'w')
for line in inputfile:
if (line != "\n"):
if (random.randint(1,selectevery) == 1):
testfile.write(line)
else:
trainfile.write(line)
inputfile.close()
trainfile.close()
testfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment