File handling 1: Read from console and write to file

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

import sys

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

print("Enter text. (Enter 'Stop' to quit)")
while(True):
Line = input()

if(Line=='Stop'):
break

fs.write(Line+'\n')

fs.close()

No comments:

Post a Comment

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

Anu