This Python script reads a text file and provides a basic analysis by counting the number of lines, words, and characters in the file.
-
Make sure you have Python installed on your system.
-
Save the script as
text_file_analyzer.py
in your desired directory. -
Run the script using a terminal or command prompt.
-
The script will prompt you to enter the path of the text file you want to analyze.
-
After entering the file path, the script will display the following information:
- Number of lines in the file
- Number of words in the file
- Number of characters in the file
Suppose you have a text file named sample.txt
with the following content:
This is a sample text file. It contains multiple lines of text. Let's see how the analyzer handles it.
Running the script and providing the path to sample.txt
would output:
Number of lines: 3
Number of words: 17
Number of characters: 96
This script provides a basic analysis for simple text files. It may not handle complex file formats or special cases.