BrokenLegMike

Using "or" operator in Python

Discussion created by BrokenLegMike on Jun 13, 2011
Latest reply on Jun 13, 2011 by lpinner
I'm trying to use operators in a python if/else statement. It's not doing what I want it to do. Basically, I am looping through a bunch of mxd's and saving certain layer files in each one. The mxd's all use the same base layers (ie Lakes, Creeks, Powerlines, etc) The other layers are random from one mxd to another. I want to save the layer files of the random layers, not the base layers. My tactic is to do something like



if lyr.name != "Lakes" or "Creeks" or "Powerlines":
    lyr.saveACopy(r"Z:\ESRI\Figure_Sourcing\Figures\Layers\\" + lyr.name, '9.3')



To me, this should save anything that does not equal to Lake, Creeks, Powerlines...

However, when I use the "or" operator, it ignores the whole syntax and saves every layer in the mxd. I guess I could use a bunch of if/else statements to weed out the ones I want, but that seems a little inefficient to me. Can any suggest a better way?

Thanks,
Mike

Outcomes