Skip to content

Commit

Permalink
Update fileinfo.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong199 committed Aug 15, 2019
1 parent aa28162 commit 791e09b
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions fileinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,22 @@
if sys.version_info >= (3, 0):
raw_input = input

try_count = 16

while try_count:
file_name = raw_input("Enter a file name: ") # pick a file you have
fhand = open(file_name)
count = 0
for lines in fhand:
count = count + 1
fhand = open(file_name)
inp = fhand.read()
t_char = len(inp)
try_count >>= 1
try:
file_stats = os.stat(file_name)
print ("This is os.stat",file_stats)
break
except OSError:
print ("\nNameError : [%s] No such file or directory\n", file_name)

if try_count == 0:
print ("Trial limit exceeded \nExiting program")
file_name = raw_input("Enter a file name: ") # pick a file you have
count = 0
t_char = 0
try:
with open(file_name) as f:
line = f.readline()
t_char += len(line)
while line:
count += 1
line = f.readline()
t_char += len(line)
except FileNotFoundError as e:
print(e)
sys.exit()


file_stats = os.stat(file_name)
# create a dictionary to hold file info
file_info = {
'fname': file_name,
Expand Down

0 comments on commit 791e09b

Please sign in to comment.