-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (35 loc) · 875 Bytes
/
main.py
File metadata and controls
41 lines (35 loc) · 875 Bytes
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
32
33
34
35
36
37
38
39
40
41
import logging
import sys
import os
import time
def count_lines(filename):
"""
Count the number of lines in file. If the file can't be
opened, it should be treated the same as if it was empty.
"""
ifile = None
try:
ifile = open(filename, "r", encoding="utf-8")
lines = ifile.readlines()
except TypeError as exp:
logging.error(exp)
return 0
except IOError as exp:
logging.error(exp)
return 0
except UnicodeDecodeError as exp:
logging.error(exp)
return 0
else:
# print(lines)
return len(lines)
finally:
if ifile:
ifile.close()
if len(sys.argv) < 2:
print("main.py file1 file2 ...")
exit()
for arg in sys.argv[1:]:
print(os.path.abspath(arg))
print(time.ctime(os.path.getctime(arg)))
print(count_lines(arg))