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

makeTextFile.py

时间:2015-07-25 13:41:42      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享

 

 

>>> import os
>>> ls = os.linesep
>>> # get filename
>>> while True:
    fname = input(Enter file name: )
    if os.path.exists(fname):
        print("*** ERROR: ‘%s‘ already exists" % fname)
    else:
        break

    
Enter file name: dinghong
*** ERROR: dinghong already exists
Enter file name: hongding
>>> # get file content (text) lines
>>> all = []
>>> print ("\nEnter lines (‘.‘ by itself to quit).\n")

Enter lines (. by itself to quit).

>>> # loop until user terminates input
>>> while True:
    entry = input(> )
    if entry == .:
        break
    else:
        all.append(entry)

        
> 
> 
> .
>>> 

 

makeTextFile.py

标签:

原文地址:http://www.cnblogs.com/hhj187/p/4675717.html

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