#!/usr/bin/python
'makeTextFile.py -- create text file'
import os,sys
ls = os.linesep
while True:
if os.path.exists('a'):
print "ERROR: '%s' already exists" % 'a'
# break
sys.exit()
else:
break
all = []
print "\nEnter lines ('.' by itself to quit). \n"
while True:
entry = raw_input('> ')
if entry == '.':
break
else:
all.append(entry)
fobj = open('a', 'w')
fobj.writelines(['%s%s' % (x, ls) for x in all])
fobj.close()
print 'DONE!'
#!/usr/bin/python
'readTextFile.py'
fname = raw_input('Enter filename: ')
print
try:
fobj = open(fname, 'r')
except IOError, e:
print "*** file open error:", e
else:
for eacheline in fobj:
print eachline,
fobj.close()
阅读(1653) | 评论(0) | 转发(0) |