아래 코드에서 다음과 같은 문제가 있습니다. 어디에서 잘못되었는지 입력 해주십시오.파일 작업이 실패합니다.
change_ignore_base.txt 및 change_ignore_base.txt가 생성되지 않고 어디로 잘못됩니까?
chagne_ignore에 "\ r"과 "\ n"이 붙어있는 것을 볼 수 있습니다. 그들을 제거하고 나중에 검색에 사용할 수있는 변수에 넣는 것이 현명한 방법입니다.
change_ids.txt
206061
150362
147117
147441
143446
200912
change_ignore.txt
150362
147117
147441
143446
200914
코드 여기
import os
import subprocess
from subprocess import check_call
def sync (base_change):
# open a file
with open('change_ignore.txt') as f:
change_ignore = f.readlines()
print "change_ignore"
print change_ignore
with open('change_ids.txt') as f:
lines = f.readlines()
for line in lines:
line=line.strip()
print line
if line <= base_change:
print "IN line<=base_change"
print line
with open("change_ignore_base.txt", "a") as myfile:
myfile.write(line)
if line in change_ignore:
print "IN change_ignore"
print line
with open("change_ignore_file.txt", "a") as myfile:
myfile.write("line")
if line > base_change and line not in change_ignore:
pass
def main():
base_change=200913
sync(base_change)
if __name__ == '__main__':
main()
당신의 조건이 충족되지 않은 추측. int와 int를 비교할 수 있습니다. btw, 그냥 "f.readlines()"또는 심지어 "for line in f"의 줄을 사용할 수 있습니다. – monkut
@monkut - 예, 조건이 잘못되었습니다. 인쇄 문이 인쇄되지 않아서 분명히 볼 수 있습니다 ... 어디서 잘못 되었는가를 알아 내기 위해 somehelp가 필요합니다. – user1927396
파일에서 행을 읽을 때 기본값으로 사용됩니다. 문자열로 읽습니다. 당신은 그것을 int와 비교할 필요가 있다면, 아마도 200913이라면, 입력 라인을 int로 변환 할 필요가 있는지를 확인하고 싶을 것이다. – monkut