In my code, I am trying to check a specific line of a config file by using linecache to read the line and an if statement to see if it is True, but for some reason it refuses to work.
I simplified the code in order to test it.
import linecache
d = linecache.getline('logconfig.dat', 2)
print(d)
if d == True:
doeslock = True
else:
doeslock = False
print(doeslock)
No matter what I try, print(d) will print True, and print(doeslock) will print False. I even tried using letters and strings instead of bools. Still didnt work. What am I missing here?
Thanks in advance guys
EDIT:
When I used strings to do the comparison, I replaced the True in the file with a y and modified the if statement to see if the d variable is 'y'
EDIT 2:
Ok guys I found the problem. Turns out the linecache returned both the line I want and the previous one for whatever reason. I separated the config into two files and now it works fine. No idea what caused this to happen but oh well. Thanks for the help!
print(repr(d))print?('True' == 'True')comparison will evaluate to the logicalTrue. So we need you to show us the entire context of your program. There are things that might have subtle changes to the behavior of the comparison or other system features that you may unintentionally invoke.