[英]Reading from a .txt file dynamically with Python
我有一個文本文件,將根據用戶在php中選擇的單選按鈕進行填充
每當我發現已添加新行時,我都從同一文本文件中讀取內容,Python腳本將其打印出來。 現在,我只是在打印它。 最終,我將根據.txt文件中的新記錄在GSM調制解調器上發送一條消息。 現在,我只是打印它以確保可以識別新記錄。
這是我正在使用的代碼。 它工作正常。
def main():
flag = 0
count = 0
while flag == 0:
f = open('test.txt', 'r')
with open('test.txt') as f:
for i, l in enumerate(f):
pass
nol = i + 1
if count < nol:
while count <= nol:
f = open('test.txt', 'r')
a = f.readlines(count)
if count == 0:
print a[0]
count = count+2
else:
print a[count-1]
count = count+1
if __name__ == '__main__':
main()
我想知道是否有更好的方法可以做到這一點。
另外,php將繼續寫入文件。 python將繼續從中讀取。 這會引起沖突嗎? 由於多個實例是開放的?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.