Python检查txt变量循环

时间:2016-04-21 19:05:24

标签: python loops variables

我需要函数来检查name.txt变量,如果变量将更改print 1,如果变量2次再次更改,则需要再次打印1.它可以在python中执行吗?http://pastebin.com/Qa0ed3nM

fr = open(" plik.txt",' r')
first_length = len(str(fr.read()))
而真实:
    text = str(fr.read())
    如果(LEN(文本)= first_length!):
        fr.close()
        fw = open(" plik.txt"," w")
        fw.write(文本)
        fw.close()
        打印("完成&#34)
        打破;

1 个答案:

答案 0 :(得分:0)

可能是这个功能可以帮助:

def checkChange(FileName, oldContent):
    fSrc = open(FileName, 'r')
    actualContent = fSrc.read()
    fSrc.close()
    if actualContent != oldContent:
        print(1)
    return actualContent