fPath = raw_input('File Path:')
counter = 0;
flag = 0;
with open(fPath) as f:
content = f.readlines()
for line in content:
if flag == 0 and line.find("WECS number") or \
line.find("WECS number") or \
line.find("WECS name") or \
line.find("Manufacturer") or \
line.find("Type") or \
line.find("Nominal effect") or \
line.find("Hub height") or \
line.find("x (local)") or \
line.find("y (local)") or \
line.find("x (global)") or \
line.find("y (global)"):
if not line.find("y (global)"):
print ("Alert Last Line!");
else:
print("Alert Line!");
어떤 이유로 코드가 "경고 줄!"을 인쇄하고있는 것 같습니다. 행이 단지 "\ n"인 경우. "if and or"구조를 만들려는 의도는 line.find
에 나열된 문자열을 포함하지 않는 모든 행을 무시하는 것이 었습니다. 여기에 뭔가 잘못되었습니다 ...파이썬 파일 I/O
이 문제를 어떻게 해결할 수 있습니까?
이 codereview.stackexchange.com –
한 스타일의 힌트에 더 적합 할 수 있습니다 대신'내용 = f.readlines의(); line in content :''do''를''f''의 줄에''그냥하십시오. –