Reading from a .txt file dynamically with Python -


i have text file populated depending on radio button selected user in php

i reading same text file, whenever find new line has been added python script prints it. printing it. send out message on gsm modem based on new records in .txt file. right i'm printing make sure can identify new record.

here's code i'm using. works fine.

def main():     flag = 0     count = 0     while flag == 0:         f = open('test.txt', 'r')         open('test.txt') f:             i, l in enumerate(f):                 pass         nol = + 1         if count < nol:             while count <= nol:                 f = open('test.txt', 'r')                 = f.readlines(count)                 if count == 0:                     print a[0]                     count = count+2                 else:                     print a[count-1]                     count = count+1 if __name__ ==  '__main__':     main() 

i wondering if there better way this.

also, php keep writing file. , python keep reading it. cause clash? since multiple instance open?

according this answer can use watchdog package watch on changes in file. alternatively can use custom made solution using fcntl in unix.

first solution has advantage of being cross-platform.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -