Python记事本和autosaving?

时间:2016-10-31 00:09:22

标签: python

我一直在创建一个记事本程序只是为了好玩。我想知道如何在我的代码中创建自动保存功能。也许有循环和写入文件功能?

这是我的记事本代码:

import argparse, sys

parser = argparse.ArgumentParser()
parser.add_argument('-w', action='store_true', help='File to write to')
parser.add_argument('-o', action='store_true', help='Open File and Edit')
argument = parser.parse_args()
print('Noteleaf')

if argument.w == True:
    try:
        wF = raw_input('Write File: ')
        w = open(str(wF), 'w')
        w.write(raw_input('-> '))
        w.close()
    except:
        print('\nWrite to File Failed')
        sys.exit()

if argument.o == True:
    try:
        oF = raw_input('Open File: ') 
        o = open(str(oF), 'r')
        print(o.read())
        with open(str(oF), 'a') as addfile:
            addfile.write(raw_input(''))
        o.close()
    except:
        print('\nOpen and Edit Failed')
        sys.exit()

import os, time
time.sleep(2)
os.system('clear')

0 个答案:

没有答案