From 22704641f46f5c4fa1cb546a49fa7405987f9747 Mon Sep 17 00:00:00 2001 From: Lucas Ayres Date: Sun, 1 Jul 2018 16:28:21 -0300 Subject: [PATCH] Add tool for count the number of characters in a tex tile. --- README.md | 2 ++ tools/count_characters.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tools/count_characters.py diff --git a/README.md b/README.md index c91afe4..7558a9b 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ A collection of [Python](https://www.python.org) utilities and tools. - [calculate_age.py](https://github.com/lucasayres/python-tools/blob/master/tools/calculate_age.py) - Calculate age from date of birth. +- [count_characters.py](https://github.com/lucasayres/python-tools/blob/master/tools/count_characters.py) - Count the number of characters in a text file. + - [email_web_crawler.py](https://github.com/lucasayres/python-tools/blob/master/tools/email_web_crawler.py) - Web crawler for grabbing emails from a website. - [merge_pdfs.py](https://github.com/lucasayres/python-tools/blob/master/tools/merge_pdfs.py) - Combine multiple pdfs to single pdf. diff --git a/tools/count_characters.py b/tools/count_characters.py new file mode 100644 index 0000000..720a369 --- /dev/null +++ b/tools/count_characters.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +def count_characters(file): + """Count the number of characters in a text file. + + Args: + file (str): Path of a fext file. + + Returns: + int: Return number of characters in a text file. + + """ + with open(file) as f: + lines = f.readlines() + return len(''.join([l for l in lines]))