請您需要您的幫助,我想將compy中的某些特定行從compy複製到另外兩個文件。 變量n和p是全局的。 這裏是我的代碼:我發現文件末尾是空的,python
def files():
i = 1
X = 1
f90 = open('C:\Users\Homura\Desktop\python\data90.txt' , 'w')
f10 = open('C:\Users\Homura\Desktop\python\data10.txt' , 'w')
f = open('C:\Users\Homura\Desktop\python\TData.txt' , 'r')
while True:
line = f.readline()
if line.startswith('0'):
while i <= n: # taking 90% of negative tweets and writing them in f90
f90.write(line)
i += 1
while i != n: #putting the rest of the negative tweets (10%) in the f10 file
f10.write(line)
i += 1
elif line.startswith('1'):
while (x <= p): # taking 90% of positive tweets and writing them in f90
f90.write(line)
x += 1
while (x != p): #putting the rest of the positive tweets (10%) in the f10 file
f10.write(line)
x += 1
f.close()
f10.close()
f90.close()
return f10 , f90
請解釋一下你的問題,你嘗試過什麼,你想要什麼程序做的,什麼叫「compy」是什麼意思? – Elisha
s/wanrt /想要s/compy/copy? – doctorlove
也許如果你可以從你的文件中提取樣本行,我們可以幫助你更多。 – GMPrazzoli