makeTextFile.py

 

 

 

>>> 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)

        
> 
> 
> .
>>> 

 

posted @ 2015-07-25 13:08  hhj187  阅读(290)  评论(0编辑  收藏  举报