How do I get a line of the what the console returns (string) and place in a variable?
问题 I have code that is using telnet and requires a login. If the login is incorrect, it returns "Incorrect login" to the console. I want to catch this exception and skip it so it doesn't stop the program. What I tried is below: try: session.write("username".encode('ascii') + b"\r") session.write("password".encode('ascii') + b"\r") ***this is the point where the console will return "Incorrect login"*** except sys.stdout == "Incorrect login": print(sys.stdout) pass else: **Rest of the code** It