Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 2nd, 2012  |  syntax: None  |  size: 0.99 KB  |  views: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import sys
  2. import csv
  3. import getopt
  4. import math
  5. import random
  6.  
  7. counter = 0
  8. filename = ""    
  9. k = 0
  10.  
  11. def usage():
  12.     print '$> python generaterawdata.py <required args> [optional args]\n' + \
  13.         '\t-f <#>\t\tFilename\n' + \
  14.         '\t-k <#>\t\tk\n'
  15.  
  16. def handleArgs(args):
  17.     # set up return values
  18.     try:
  19.         optlist, args = getopt.getopt(args[1:], 'f:k:')
  20.     except getopt.GetoptError, err:
  21.         print str(err)
  22.         usage()
  23.         sys.exit(2)
  24.    
  25.     for key, val in optlist:
  26.         # first, the required arguments
  27.         if   key == '-f':
  28.             filename = "" + val
  29.         elif key == '-k':
  30.             k = int(val)
  31.    
  32.     # check required arguments were inputted  
  33.     if k < 0:
  34.         usage()
  35.         sys.exit()
  36.    
  37.     print "File is", filename
  38.     print "k is", k
  39.     reader = csv.reader(open(filename,"r"))
  40.     lines = []
  41.     for row in reader:
  42.         lines.append(row)
  43.     print lines
  44.     return (k)
  45.  
  46. handleArgs(sys.argv)
clone this paste RAW Paste Data