FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python_Basics/python_programs/line_count.py at master · learnbyexample/Python_Basics · GitHub
This repository was archived by the owner on Dec 29, 2020. It is now read-only.
learnbyexample
/
Python_Basics
Public archive
Notifications
You must be signed in to change notification settings
Fork
196
Star
614
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Python_Basics
/
python_programs
/
line_count.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (16 loc) · 698 Bytes
Breadcrumbs
Python_Basics
/
python_programs
/
line_count.py
Copy path
File metadata and controls
21 lines (16 loc) · 698 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python3
import
sys
,
pathlib
,
subprocess
,
re
if
len
(
sys
.
argv
)
!=
2
:
sys
.
exit
(
"Error: Please provide exactly one filename as argument"
)
program_name
=
sys
.
argv
[
0
]
filename
=
sys
.
argv
[
1
]
if
not
pathlib
.
Path
(
filename
).
is_file
():
sys
.
exit
(
"File '{}' not found"
.
format
(
filename
))
if
re
.
search
(
r'line_count.py'
,
program_name
):
lc
=
subprocess
.
getoutput
(
'wc -l < '
+
filename
)
print
(
"No. of lines in '{}' is: {}"
.
format
(
filename
,
lc
))
elif
re
.
search
(
r'word_count.py'
,
program_name
):
wc
=
subprocess
.
getoutput
(
'wc -w < '
+
filename
)
print
(
"No. of words in '{}' is: {}"
.
format
(
filename
,
wc
))
else
:
sys
.
exit
(
"Program name '{}' not recognized"
.
format
(
program_name
))
Back
|
FazBrowse Home
|
New Git URL