I am new to Python and trying to build a practice project that reads some XML. For some reason this if statement is triggered even for blank whitespace lines:
if '<' and '>' in line:
Any ideas why?
Your code says (parethesised for clarity):
if '<' and ('>' in line):
Which evaluates to:
if True and ('>' in line):
Which in your case evaluates to true
when you don't intend to. So, try this instead (parenthesis are optional, but added for clarity):
if ('<' in line) and ('>' in line):
You probably want:
if ('<' in line) and ('>' in line):
Your version is being interpreted as this:
if ('<') and ('>' in line):
which is probably not what you meant.
Use parenthesis to make things super-obvious.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With