私はPythonで小さな(ばかげた)問題を抱えています。テキストファイルを転送するためにクライアントサーバープログラムに取り組んでいます。現在、ファイルを受信しようとするといくつかの問題が発生します。私の問題は、ユーザーにファイルを保存するかどうかを尋ねたときに、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」を入力しても、正解を入力するように指示されます。どんな助けでもいただければ幸いです。ありがとうございました!