File Handling 5: Display nth line of a file

# Display nth line of a file
# Use command line arguments

import sys

fname = sys.argv[1]
fs = open(fname, "r")

Nline = int(input("Enter line to print : "))

L = fs.readlines()

print("File:", fs.name)
print("Line number -", Nline)
print(L[Nline-1])

fs.close()

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu