0
dd = (re.findall(r'">County<(.*?)</td>', lmth2))
if not dd:
    dd = (re.findall(r'<small>Location in <a(.*?)</td>',lmth2)
          if not dd:
          county.append("")
          fin.append(name[o]+';'+address[o]+';'+city[o]+';'+stateorg[o]+';'+county[o]+';'+phone[o]+';'+website[o])
          continue
    else:
        ee = (re.findall(r'title="(.*?) County', dd[0]))
        county.append(ee[0])
        fin.append(name[o]+';'+address[o]+';'+city[o]+';'+stateorg[o]+';'+county[o]+';'+phone[o]+';'+website[o])

I'm trying to stack IF NOTs together to find the find result. If

If dd does not come up as a match then I want to try the second scenario. If that doesn't come up with a match then I want, for right now, for it to show it as nothing comes up and to set up the line to be saved to the file. If it does come up with a match than I need it continue on find the second level of the search with ee = (re.findall...)

Until I found the second possible scenario to search for everything had been working find but then I found another possible thing I need to look for so I'm trying to add it into the program and I keep getting an Invalid Syntax coming back on the : on the second

if not dd:

This is one that is WAY beyond me. I'm not use to having this trouble with stacked if's when I use to use VB6. Python seems to be handling things a bit differently.

confused
  • 1,283
  • 6
  • 21
  • 37
  • Also... Depending on what you're trying to do, it might be easier to simplify your logic. Remember: `not A and not B` is the same as `not(A or B)`. See [DeMorgan's Theory](http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/demorgan.html) for more info. – Basic Oct 01 '16 at 01:00
  • I'm wanting it to test condition one before it even tries to set up condition two. If condition one exists then condition two won't. Hence the pecking order and the approach I'm attempting to use. – confused Oct 01 '16 at 01:03
  • You can do all of that in a single statement. Python Uses short-circuiting for operators. As soon as it finds a condition that will prevent a block being executed, it stops... say you have... `if something() and something_else():`... During executing, if `something()` returns `False`, `something_else()` will never be executed/tested. I've put functions in here as I assume that's what your doing. plain variables work just the same way. See http://stackoverflow.com/questions/2580136/does-python-support-short-circuiting . And a wiki link: https://en.wikipedia.org/wiki/Short-circuit_evaluation – Basic Oct 01 '16 at 01:09

1 Answers1

0

Indentation is syntactically significant in Python. Unlike languages where blocks are determined by tokens like begin and end or { and }, in Python blocks are determined by indents and dedents.

As such, you cannot arbitrarily indent Python code. Whenever Python encounters a line that is indented further than the line above it, it expects that to be the first line of a new block. The issue you have is that inside the first if statement you have already established the indentation level of that block with the line dd = ..., and then you've indented the next if statement even further, while it should be at the same indentation level.

If you remove the extra indent on the second if not dd: line, it should no longer have a syntax error.

Miles Rout
  • 1,204
  • 1
  • 13
  • 26
  • I just removed the extra indent and I'm still getting the same error on the same : – confused Oct 01 '16 at 00:54
  • You also have unmatched brackets on the previous line, which is probably why your text editor indented the next line more than it should have. – Miles Rout Oct 01 '16 at 01:05
  • Remove the first bracket on the line before the too-heavily-indent `if`: replace `dd = (re.findall...` with `dd = re.findall...`. – Miles Rout Oct 01 '16 at 01:06
  • You got it this time. I didn't even see that. I'm surprised it was forcing the error down to the next line. It seems like it should have put the error up on the dd= ( line versus on the if not line. Thanks. – confused Oct 01 '16 at 01:17