-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlines.py
31 lines (27 loc) · 796 Bytes
/
lines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
def main():
filename = arguments()
if filename:
count = 0
with open(filename, 'r') as file:
for line in file:
line = line.strip() # Strip whitespace including newline characters
if line and not line.startswith('#'):
count += 1
print("Total lines of code in your file are:", count)
def arguments():
if len(sys.argv) == 1:
print('Too few arguments')
sys.exit(1)
elif len(sys.argv) > 2:
print('Too many arguments')
sys.exit(1)
else:
filename = sys.argv[1]
if filename.endswith('.py'):
return filename
else:
print('Not a python file')
sys.exit(1)
if __name__ == '__main__':
main()