码迷,mamicode.com
首页 > 其他好文 > 详细

核心编程答案(第三章)

时间:2016-05-01 23:17:36      阅读:384      评论: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!