首页 > 其他 > 详细

核心编程答案(第三章)

时间:2016-05-01 23:15:26      阅读:431      评论:0      收藏:0      [点我收藏+]

3-10

#!/usr/bin/env python
# encoding: utf-8

import os
ls = os.linesep
fname = raw_input(‘Enter file name: ‘)

all = []

try:
    fobj = open(fname, ‘r‘)
    print "‘%s already exists‘" % fname
except IOError, e:
    print "\nEnter lines (‘.‘ by itself to quite). \n"
    while True:
        entry = raw_input(‘>‘)
        if entry == ‘.‘:
            break
        else:
            all.append(entry)
    fobj = open(fname, ‘w‘)
    fobj.writelines(‘%s%s‘ % (x, ls) for x in all)
    fobj.close()
    print "Done!"

 

核心编程答案(第三章)

原文:http://www.cnblogs.com/ohmydenzi/p/5451419.html

踩
(1)
赞
(1)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!