[GRASS-dev] Copying Landsat MTL file(s) inside the cell_misc directory -- Python scripting
peter.zamb at gmail.com
Tue May 14 06:43:55 PDT 2013
On Tue, May 14, 2013 at 1:25 PM, Nikos Alexandris
<nik at nikosalexandris.net> wrote:
> I know the following is a pure python question -- still, can someone shed some
> light on why is there such a difference between
> if 'DATE_ACQUIRED' or 'ACQUISITION_DATE' in line:
> if 'DATE_ACQUIRED' in line or 'ACQUISITION_DATE' in line:
Your error is due to the precedence of the operator, what it is really
written in the first row is:
if ( ('DATE_ACQUIRED') or ('ACQUISITION_DATE' in line) ):
Therefore the first statement 'DATE_ACQUIRED' is always True because
is a string that it is not empty.
Let me define a function like:
>>> def istrue(obj):
... if obj:
... return True
... return False
Now If you try with an empty string you have:
If you try with a string that contains something you get:
Therefore the second is correct because you check if the first string
is contained or the second string is contained in the line.
An easy way to debug this kind of problems is to use python debugger
 (possibly the ipython dubugger! ) in the line before, like:
import ipdb; ipdb.set_trace() # or import pdb; pdb.set_trace()
# set_trace will open a terminal to debug your program from this point...
if 'DATE_ACQUIRED' in line or 'ACQUISITION_DATE' in line:
Have fun with python! :-)
All the best.
More information about the grass-dev