Search code examples
pythonesri

Meaning of "if x == "#" or not x:"


So I'm reading through some code, and I come across this statement. "x", in this case, is user input so I assume it is some form of validation, but what does it do? x == not x doesn't make any sense, and what does "#" mean?

Here is the offending chunk of code:

def main(*argv):
try:

    #Get FC and Fields
    inputFC = arcpy.GetParameterAsText(0)
    if inputFC =="#" or not inputFC:
        inputFC = "Tooldata\\InputFC" # provide a default value if unspecified

Solution

  • inputFC == "#" or not inputFC is a boolean expression with two parts:

    1. inputFC == "#" – This checks whether inputFC equals to the string "#".
    2. not inputFC – This checks whether inputFC is not trueish which means that it’s not not empty (i.e. empty).

    Both conditions are combined using the or operator, so just one condition needs to match to make the whole expression evaluate to true.