당신의 도움이 필요합니다. 필자는 파일의 특정 줄을 다른 두 줄로 컴파일하려고합니다. 변수 n과 p는 전역 변수입니다. 그들은 동일한 것으로 가정된다 -끝에 파일이 비어 있습니다. 파이썬
대문자X
와 소문자
x
가 작은 관찰,
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/want s/compy/copy? – doctorlove
파일에서 샘플 라인을 제안 할 수 있다면 더 많이 도와 드릴 수 있습니다. – GMPrazzoli