Skip to content

Commit 3ab2cf9

Browse files
committed
file stats
1 parent 0f4a299 commit 3ab2cf9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lab-12/file-stats.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import os
2+
23
def stats(file_path):
34
file = open(file_path, "r")
45
file_data = file.read()
56
file_characters = len(file_data)
67
file_lines = int(sum(1 for line in file_data) / 10)
78
file_words = len(file_data.split())
9+
print(f"File statistics for {os.path.basename(file_path)}: \n\
10+
{file_characters} characters\n\
11+
{file_words} words\n\
12+
{file_lines} lines")
813

914
stats(os.path.expanduser('~') + "\\src\\python-programming\\lab-12\\test.txt")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy