파이썬에서 아주 작은 (어리석은) 문제가 있습니다. 텍스트 파일을 전송하기 위해 클라이언트 - 서버 프로그램에서 작업 중입니다. 현재는 몇 가지 문제가 있습니다. 파일을 받으려고합니다. 그는 파일을 저장하고 싶다면 나는 그가 Y 들어가거나 작동하지 않는 Y, 여기에 조각 경우에도 사용자에게 물어 때 내 문제는 다음과 같습니다파이썬 오류 : 문자열 검증을위한 명백한 조건이 작동하지 않습니다.
print "Listening on input"
a = 1
while a == 1:
pipe = open(fifoclient,'r')
dr, dw, de = select.select([pipe], [], [], 0)
if dr:
content = pipe.read()
liste = content.split("delimiter")
expediteur = liste[1]
filecont = liste[2]
print "You received a file from : " + expediteur + ". Wanna save it?"
answer = raw_input("O/N: ")
while answer != "O" or answer != "N" or answer != "o" or answer != "n":
print "Please enter a correct answer:\n"
answer = raw_input("O/N: ")
if answer == "O" or answer == "o":
fileoutpath = str(raw_input("please enter the complete path for where you want to save the file to: "))
while os.path.exists(fileoutpath):
print "THe file already exists, chose another path:\n"
fileoutpath = str(raw_input("please enter the complete path for where you want to save the file to: "))
fileout = open(fileoutpath,'w')
fileout.write(filecont)
fileout.close()
else:
a = 0
은 O/N을 요청하면 문제가 (Oui/Non 그것은 프랑스어 :)). "o"또는 "O"를 입력해도 정답을 입력해야합니다. 도움이 될 것입니다. 고맙습니다!
이러한 종류의 문제가 발생하면 모든 사용자 입력/응답을 얻은 후 소문자 (또는 대문자)로 변환 한 다음 다른 사례를 염려하지 않고 간단한 비교를 수행하는 것이 좋습니다. – Levon