3-8

 1 #3-8
 2 "makeTextFile.py -- create text file"
 3 
 4 import os
 5 ls = os.linesep
 6 
 7 #get filename
 8 fname = raw_input()
 9 while True:
10 
11   if os.path.exists(fname):
12     print "ERROR: '%s' already exists" % fname
13   else:
14     break
15 all = []
16 print "\nEnter lines ('.' by itself to quit).\n"      
17 
18 while True:
19   entry = raw_input('newline:')
20   if entry == '.':
21     break
22   else:
23     all.append(entry)
24 
25 fobj = open(fname, 'w')
26 fobj.writelines(['%s%s' % (x, ls) for x in all])
27 fobj.close()
28 print "DONE!" 
View Code

相关文章: