嗨,我正在做一个输入command
的程序,但即使输入是明确的“A”但它什么都不做并继续。这是代码:
import os
import socket
import time
print("The Program is starting")
print("")
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print("Socket created")
print("")
def command_taking():
command = input("Command: ")
print(command)
time.sleep(0.1)
if command == "A":
print("of")
target = str(input("Ip of the target: "))
print("")
print("The target is", target)
command_taking()
os.system("pause")
答案 0 :(得分:0)
看来,你已经受到了Python bug的攻击:input()
has trailing carriage return on windows。 The only version that has that bug is 3.2.0,将您的Python更新为更新版本,或使用command = command.rstrip("\n\r")
作为解决方法。