Code:
import os
PassWorD = open('password')
print(PassWorD, 'is type: ', type(PassWorD))
passWord = PassWorD.read()
print(passWord, 'is type: ',type(passWord))
secretPassword = input("enter your password: ")
print(secretPassword, 'is type: ', type(secretPassword))
if passWord == secretPassword:
print("true")
else:
print("false")
PassWorD.close()
<_io.TextIOWrapper name='password' mode='r' encoding='UTF-8'> is type: <class '_io.TextIOWrapper'>
foo
is type: <class 'str'>
enter your password: foo
foo is type: <class 'str'>
false
The conditional check should be testing the value of two objects of the string class. PassWord is converted to a string class object by assignment to passWord, secretPassword is a string class object. Both appear to contain the string 'foo', yet the conditional test yields a false response. WTFO? Can any pythonistas interpret this result?