Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # count the number of commas in a file and print if the number of commas is different than expected
- import argparse
- parser = argparse.ArgumentParser()
- parser.add_argument("filename", help="filename")
- parser.add_argument("commas", help="number of expected commas", type=int)
- args = parser.parse_args()
- file = args.filename
- number_commas = int(args.commas)
- with open(file, 'r') as csv_file:
- for line in csv_file:
- lc = line.count(',')
- if (lc != number_commas):
- print(lc,' - ',line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement