Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: file_character_count.py
- # Author: Jeoi Reqi
- """
- File Character Count Script
- This script reads text from a specified file ('texty.txt') in the same directory
- and counts the number of characters in the text. It utilizes a function,
- count_characters, to perform the character counting operation.
- Requirements:
- - Python 3
- Usage:
- 1. Save the 'texty.txt' file in the same directory as the script.
- 2. Replace 'texty.txt' with the actual file name in the script if needed.
- 3. Run the script.
- 4. The script will display the number of characters in the text file.
- """
- def count_characters(file):
- """Count the number of characters in a text file.
- Args:
- file (str): Path of a text file.
- Returns:
- int: Number of characters in the text file.
- """
- with open(file, encoding='utf-8') as f:
- content = f.read()
- return len(content)
- def main():
- # Specify the file path
- file_path = 'texty.txt' # Replace 'texty.txt' with the actual file name if needed
- # Count characters
- character_count = count_characters(file_path)
- # Display the result
- print(f"Number of characters in the text file: {character_count}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement