- 论坛徽章:
- 0
|
'maketextfile.py --- create text file'
import os
ls = os.linesep
# get filename
while True:
if os.path.exists('C:\Python26\make.log'):
print "ERROR: '%s' already exists" % ('C:\Python26\make.log')
else:
break
# get file content (text) lines
all=[]
print"\nEnter lines ('.'by itselef to quit).\n"
# loop until user terminates input
while True:
entry = raw_input('>')
if entry == '.':
break
else:
all.append(entry)
# write lines to file with proper line-ending
fobj = open(r'C:\Python26\make.log','w')
fobj.writelines(['%s%s' % (x,ls) for x in all])
fobj.close()
print 'DONE!'
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103983/showart_2082183.html |
|