File Handling 2: Read from file and display

# Read from console and write to file
# Use command line arguments

import sys

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

print("File:", fs.name)

while(True):
Line = fs.readline()

if not Line:
break

print(Line)

fs.close()


# Read from console and write to file
# Use command line arguments

import sys

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

print("File:", fs.name)

L = fs.readlines()
 
for Line in L:
  print(Line)

fs.close()

No comments:

Post a Comment

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

Anu