Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. # count the number of commas in a file and print if the number of commas is different than expected
  2. import argparse
  3. parser = argparse.ArgumentParser()
  4. parser.add_argument("filename", help="filename")
  5. parser.add_argument("commas", help="number of expected commas", type=int)
  6. args = parser.parse_args()
  7.  
  8. file = args.filename
  9. number_commas = int(args.commas)
  10.  
  11. with open(file, 'r') as csv_file:
  12. for line in csv_file:
  13. lc = line.count(',')
  14. if (lc != number_commas):
  15. print(lc,' - ',line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement