Skip to content

Commit 1f4548e

Browse files
committed
added print function
1 parent e6f6020 commit 1f4548e

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

check_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def usage():
2222
def readfile(filename):
2323
with open(filename, 'r') as f: # Ensure file is correctly closed under all circumstances
2424
line = f.read()
25-
print (line)
25+
print(line)
2626

2727
def main():
2828
if len(sys.argv) >= 2: # Check the arguments passed to the script

fileinfo.py

+32-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
# Script Name : fileinfo.py
22
# Author : Not sure where I got this from
33
# Created : 28th November 2011
4-
# Last Modified :
4+
# Last Modified :
55
# Version : 1.0
6-
# Modifications :
6+
# Modifications :
77

88
# Description : Show file information for a given file
99

1010

1111
# get file information using os.stat()
1212
# tested with Python24 vegsaeat 25sep2006
13+
from __future__ import print_function
1314
import os
15+
import sys
1416
import stat # index constants for os.stat()
1517
import time
16-
# pick a file you have ...
17-
file_name = raw_input("Enter a file name: ")
18-
file_stats = os.stat(file_name)
18+
19+
try_count = 16
20+
while try_count:
21+
file_name = raw_input("Enter a file name: ") # pick a file you have ...
22+
try_count >>= 1
23+
try :
24+
file_stats = os.stat(file_name)
25+
break
26+
except OSError:
27+
print ("\nNameError : [%s] No such file or directory\n" %file_name)
28+
29+
if try_count == 0:
30+
print ("Trial limit exceded \nExiting program")
31+
sys.exit()
1932
# create a dictionary to hold file info
2033
file_info = {
2134
'fname': file_name,
@@ -25,23 +38,24 @@
2538
'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_CTIME]))
2639
}
2740
print
28-
print "file name = %(fname)s" % file_info
29-
print "file size = %(fsize)s bytes" % file_info
30-
print "last modified = %(f_lm)s" % file_info
31-
print "last accessed = %(f_la)s" % file_info
32-
print "creation time = %(f_ct)s" % file_info
41+
print ("file name = %(fname)s" % file_info)
42+
print ("file size = %(fsize)s bytes" % file_info)
43+
print ("last modified = %(f_lm)s" % file_info)
44+
print ("last accessed = %(f_la)s" % file_info)
45+
print ("creation time = %(f_ct)s" % file_info)
3346
print
3447
if stat.S_ISDIR(file_stats[stat.ST_MODE]):
35-
print "This a directory"
48+
print ("This a directory")
3649
else:
37-
print "This is not a directory"
38-
print
39-
print "A closer look at the os.stat(%s) tuple:" % file_name
40-
print file_stats
41-
print
42-
print "The above tuple has the following sequence:"
43-
print """st_mode (protection bits), st_ino (inode number),
50+
print ("This is not a directory")
51+
print ()
52+
print ("A closer look at the os.stat(%s) tuple:" % file_name)
53+
print (file_stats)
54+
print ()
55+
print ("The above tuple has the following sequence:")
56+
print ("""st_mode (protection bits), st_ino (inode number),
4457
st_dev (device), st_nlink (number of hard links),
4558
st_uid (user ID of owner), st_gid (group ID of owner),
4659
st_size (file size, bytes), st_atime (last access time, seconds since epoch),
4760
st_mtime (last modification time), st_ctime (time of creation, Windows)"""
61+
)

0 commit comments

Comments
 (0)