Skip to content

Commit f68abd7

Browse files
Merge pull request geekcomputers#105 from Henocks/patch-15
slight update
2 parents 498b1e3 + 77d6d50 commit f68abd7

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

fileinfo.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import time
1818

1919
try_count = 16
20+
2021
while try_count:
2122
file_name = raw_input("Enter a file name: ") # pick a file you have
2223
try_count >>= 1
@@ -29,35 +30,32 @@
2930
if try_count == 0:
3031
print ("Trial limit exceded \nExiting program")
3132
sys.exit()
33+
3234
# create a dictionary to hold file info
3335
file_info = {
3436
'fname': file_name,
3537
'fsize': file_stats[stat.ST_SIZE],
36-
'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p",
37-
time.localtime(file_stats[stat.ST_MTIME])),
38-
'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p",
39-
time.localtime(file_stats[stat.ST_ATIME])),
40-
'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p",
41-
time.localtime(file_stats[stat.ST_CTIME]))
38+
'f_lm' : time.strftime("%d/%m/%Y %I:%M:%S %p",
39+
time.localtime(file_stats[stat.ST_MTIME])),
40+
'f_la' : time.strftime("%d/%m/%Y %I:%M:%S %p",
41+
time.localtime(file_stats[stat.ST_ATIME])),
42+
'f_ct' : time.strftime("%d/%m/%Y %I:%M:%S %p",
43+
time.localtime(file_stats[stat.ST_CTIME]))
4244
}
4345

44-
print
45-
print ("file name = %(fname)s", file_info)
46+
print ("\nfile name = %(fname)s", file_info)
4647
print ("file size = %(fsize)s bytes", file_info)
4748
print ("last modified = %(f_lm)s", file_info)
4849
print ("last accessed = %(f_la)s", file_info)
49-
print ("creation time = %(f_ct)s", file_info)
50-
print
51-
if stat.S_ISDIR(file_stats[stat.ST_MODE]):
50+
print ("creation time = %(f_ct)s\n", file_info)
5251

52+
if stat.S_ISDIR(file_stats[stat.ST_MODE]):
5353
print ("This a directory")
5454
else:
55-
print ("This is not a directory")
56-
print ()
55+
print ("This is not a directory\n")
5756
print ("A closer look at the os.stat(%s) tuple:" % file_name)
5857
print (file_stats)
59-
print ()
60-
print ("The above tuple has the following sequence:")
58+
print ("\nThe above tuple has the following sequence:")
6159
print ("""st_mode (protection bits), st_ino (inode number),
6260
st_dev (device), st_nlink (number of hard links),
6361
st_uid (user ID of owner), st_gid (group ID of owner),

0 commit comments

Comments
 (0)