def main(args): """Run the command line program.""" word_counts = Counter() for fname in args.infiles: with open(fname, 'r') as reader: update_counts(reader, word_counts) util.collection_to_csv(word_counts, num=args.num)
def main(args): """Run the command line program.""" log_lev = logging.DEBUG if args.verbose else logging.WARNING logging.basicConfig(level=log_lev, filename=args.logfile, filemode='w') word_counts = Counter() logging.info('Processing files...') for fname in args.infiles: try: logging.debug(f'Reading in {fname}...') if fname[-4:] != '.csv': msg = ERRORS['not_csv_suffix'].format(fname=fname) raise OSError(msg) with open(fname, 'r') as reader: logging.debug('Computing word counts...') update_counts(reader, word_counts) except FileNotFoundError: msg = f'{fname} not processed: File does not exist' logging.warning(msg) except PermissionError: msg = f'{fname} not processed: No read permission' logging.warning(msg) except Exception as error: msg = f'{fname} not processed: {error}' logging.warning(msg) util.collection_to_csv(word_counts, num=args.num)
def main(args): """Run the command line program.""" log_level = logging.DEBUG if args.verbose else logging.WARNING logging.basicConfig(level=log_level, filename=args.logfile) word_counts = Counter() logging.info('Processing files...') for file_name in args.infiles: logging.debug(f'Reading in {file_name}...') if file_name[-4:] != '.csv': raise OSError('The filename must end in `.csv`') with open(file_name, 'r') as reader: logging.debug('Computing word counts...') update_counts(reader, word_counts) utilities.collection_to_csv(word_counts, num=args.num)
def main(args): """Run the command line program.""" log_level = logging.DEBUG if args.verbose else logging.WARN logging.basicConfig(level=log_level, filename=args.logfile) word_counts = Counter() logging.info('Processing files...') for fname in args.infiles: logging.debug(f'Reading in {fname}...') if fname[-4:] != '.csv': msg = ERRORS['not_csv_suffix'].format(fname=fname) raise OSError(msg) with open(fname, 'r') as reader: logging.debug('Computing word counts...') update_counts(reader, word_counts) util.collection_to_csv(word_counts, num=args.num)
def main(args): """Run the command line program.""" log_lev = logging.DEBUG if args.verbose else logging.WARNING logging.basicConfig(level=log_lev, filename=args.logfile) word_counts = Counter() logging.info('Processing files...') for fname in args.infiles: try: process_file(fname, word_counts) except FileNotFoundError: msg = f'{fname} not processed: File does not exist' logging.warning(msg) except PermissionError: msg = f'{fname} not processed: No read permission' logging.warning(msg) except Exception as error: msg = f'{fname} not processed: {error}' logging.warning(msg) util.collection_to_csv(word_counts, num=args.num)
def main(args): """Run the command line program.""" word_counts = count_words(args.infile) util.collection_to_csv(word_counts, num=args.num)
def main(args): """Run the command line program.""" with args.infile as reader: word_counts = count_words(reader) utilities.collection_to_csv(word_counts, num=args.num)
def main(args): """Run the command line program.""" #with open(args.infile, 'r') as reader: # word_counts = count_words(reader) word_counts = count_words(args.infile) util.collection_to_csv(word_counts, num=args.num)